This is a migrated thread and some comments may be shown as answers.

Q2 2010 Copy and paste a relative url is turning absolute

7 Answers 113 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Robert Field
Top achievements
Rank 1
Robert Field asked on 17 Aug 2010, 12:10 PM
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

7 Answers, 1 is accepted

Sort by
0
Espen Fosshaug
Top achievements
Rank 1
answered on 18 Aug 2010, 02:41 PM
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
0
Rumen
Telerik team
answered on 18 Aug 2010, 02:56 PM
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
0
Robert Field
Top achievements
Rank 1
answered on 19 Aug 2010, 08:26 AM
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?
0
Rumen
Telerik team
answered on 19 Aug 2010, 08:35 AM
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
0
Espen Fosshaug
Top achievements
Rank 1
answered on 19 Aug 2010, 02:12 PM
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?
0
Rumen
Telerik team
answered on 23 Aug 2010, 12:39 PM
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
0
Espen Fosshaug
Top achievements
Rank 1
answered on 23 Aug 2010, 02:17 PM
Hi.

The easy way is the best way :-) I am stripping the url on save from the page. This works fine.
Thanks.
Tags
Editor
Asked by
Robert Field
Top achievements
Rank 1
Answers by
Espen Fosshaug
Top achievements
Rank 1
Rumen
Telerik team
Robert Field
Top achievements
Rank 1
Share this question
or