Q2 2010 Copy and paste a relative url is turning absolute

8 posts, 0 answers
  1. Robert Field
    Robert Field avatar
    7 posts
    Member since:
    Sep 2012

    Posted 17 Aug 2010 Link to this post

    Hi,

    We are using the latest version Q2 2010 of asp.net ajax and from what I have read in the forum you previously fixed a problem with IE where if you paste a relative url into the editor it gets turned into absolute.

    However I am experiencing the same problem in the latest version of the editor. Using IE 8 if I edit content with relative urls, copy and paste one of them it gets turned absolute. The content filters is set to "None" as I know there is one for marking urls absolute.

    Is the bug reintroduced or am I missing something?

    Thanks
  2. Espen Fosshaug
    Espen Fosshaug avatar
    18 posts
    Member since:
    Sep 2009

    Posted 18 Aug 2010 Link to this post

    Hi.

    I have almost the same problem. When I insert the image from the image manager the url is correct, but if I just move it within the editor the url turns absolute. We write text in one webpage and display it on another. Using releative URL this works fine, but it fails when they are absolute.
    I can use Properties on the image to make it back to relative, but this is easy to forget since it looks fine in the webpage where this is edited.

    Espen
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rumen
    Admin
    Rumen avatar
    12849 posts

    Posted 18 Aug 2010 Link to this post

    Hi guys,

    When copying and pasting a link or an image with a relative path in Internet Explorer, the browser automatically converts the path to absolute. The code below demonstrates how to attach to the OnClientPasteHtml event and strip the desired url path using the StripPathFilter content filter. The StripPathsFilter() method receives as a parameter an array of strings (devided by a white space) that will be stripped from the absolute path.

    <script type="text/javascript">
    function OnClientPasteHtml(sender, args)
    {
        var commandName = args.get_commandName();
        var value = args.get_value();
        
        if (commandName == "Paste")
        {
           // The StripPathsFilter() method receives as a parameter an array of strings (devided by a white space) that will be stripped from the absolute links.
            var domainName = "http://" + window.location.host; //returns the hostname and port number of the current URL
            var filter = new Telerik.Web.UI.Editor.StripPathsFilter([domainName]); //strip the domain name from the absolute path
                        
            var contentElement = document.createElement("SPAN");
            contentElement.innerHTML = value;
            var newElement = filter.getHtmlContent(contentElement);
            alert(newElement.outerHTML);
            args.set_value(newElement.outerHTML);  //set the modified pasted content in the editor
        }
    }
    </script>

    Please, note that the OnClientPasteHtml event fires the Paste command only when the StripFormattingOnPaste property is not set to "NoneSupressCleanMessage". In this case the editor does not process the pasted content and pastes it without modifications.




    All the best,
    Rumen
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Robert Field
    Robert Field avatar
    7 posts
    Member since:
    Sep 2012

    Posted 19 Aug 2010 Link to this post

    Thank you this fixes the problem with copy and pasting links, but like Espen mentions their is another problem when you move an image by dragging it, the realtive link is changed in to absolute. Do you have a fix for this?
  6. Rumen
    Admin
    Rumen avatar
    12849 posts

    Posted 19 Aug 2010 Link to this post

    Hello Robert,

    Yes, the solution for this problem is provided in the following forum thread: Image path problem, e.g.

    <script type="text/javascript">    
    function OnClientLoad(editor, args)    
    {    
       var element = document.all ? editor.get_document().body : editor.get_document();    
       var eventHandler  = document.all ? "drop" : "dragend";    
       $telerik.addExternalHandler(element, eventHandler, function(e)    
       {    
          
           setTimeout(function()    
           {    
                 
                var domainName = "http://" + window.location.host;   
                var filter = new Telerik.Web.UI.Editor.StripPathsFilter([domainName]);   
                    
                var div  = editor.get_document().createElement("DIV");    
                div.innerHTML = editor.get_html(true);    
                  
                var newElement = filter.getHtmlContent(div);  
                editor.set_html(div.innerHTML);    
          }, 300);    
       });   
    }    
       
    </script>   
    <telerik:radeditor runat="server"   
       OnClientLoad="OnClientLoad" 
       ID="RadEditor1">   
       <Content><img src="/mdc-logo.png" />test test test</Content> 
    </telerik:radeditor> 


    Best regards,
    Rumen
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Espen Fosshaug
    Espen Fosshaug avatar
    18 posts
    Member since:
    Sep 2009

    Posted 19 Aug 2010 Link to this post

    Hi.

    This works, but it is no good(almost useless) solution.
    Since the text is changed the content reloads and move the cursor to top of the text. When you have a long text this is more irritating than changing the URL manually.
    Any other solution?
  8. Rumen
    Admin
    Rumen avatar
    12849 posts

    Posted 23 Aug 2010 Link to this post

    Hi Espen,

    Indeed, the solution to replace the whole content when the drop event occurs is not fully functional because the selection is lost. What you can do is to implement your own custom content filter that will convert the absolute paths to relative when switching to HTML mode or submitting the content by firing the
    Telerik.Web.UI.Editor.StripPathsFilter([domainName]); filter of RadEditor.

    Another approach is to strip the absolute paths on the server when obtaining the content through the RadEditor1.Content property. The content is returned as a simple string and you can change the src / href values using the String.Replace server method.

    Best regards,
    Rumen
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Espen Fosshaug
    Espen Fosshaug avatar
    18 posts
    Member since:
    Sep 2009

    Posted 23 Aug 2010 Link to this post

    Hi.

    The easy way is the best way :-) I am stripping the url on save from the page. This works fine.
    Thanks.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017