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

Copy Paste Relative Links Problem

1 Answer 24 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Piyushkumar
Top achievements
Rank 1
Piyushkumar asked on 02 Dec 2010, 09:48 PM
Hi,
My relative path is like ---> "photos/pic1.jpg"... The relative links turns to absolute... I referred to posts and found your following JS function...
function OnClientPasteHtml(sender, args)
{
    var commandName = args.get_commandName();
    var value = args.get_value();
    if (commandName == "Paste")
    {
        var domainName = "http://" + window.location.host; //returns the hostname and port number of the current URL
        ... ... ... ... ...


But the problem is... When it turns to absolute, the URLs become as shown below depending on server.
I have URLs like --> http://www.xyz.com/sms_server1/photos/pic1.jpg  and http://www.xyz.com/sms_live/photos/pic1.jpg

Your following code --> var domainName = "http://" + window.location.host; ///// Returns the hostname and port number of the current URL

But it does not return ---->    sms_server1    OR     sms_live   etc...
How can I replace it...

Thanks,
Piyush

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 03 Dec 2010, 05:05 PM
Hi Piyush,

JavaScript window.location.href property enables you to get or set the current URL location of the web browser. You can get the current URL location by accessing the href property of location object, extract the path that you want to be stripped and pass it through the StripPathsFilter filter:

<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 location = window.location.href;
            var domainName = location.substring(0, location.lastIndexOf("/")) //returns the hostname and port number of the current URL
            var filter = new Telerik.Web.UI.Editor.StripPathsFilter([domainName]); 
 
            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>
<telerik:RadEditor runat="server"
OnClientPasteHtml="OnClientPasteHtml"
ImageManager-ViewPaths="~/Images" ImageManager-UploadPaths="~/Images"
ID="RadEditor1">
    <Content><img alt="" src="/editorQ32010/Images/Deisy.jpg" /></Content>
</telerik:RadEditor>


Regards,
Rumen
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Editor
Asked by
Piyushkumar
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or