Use absolute paths for images and relative path for links?

6 posts, 0 answers
  1. Mike
    Mike avatar
    14 posts
    Member since:
    Nov 2005

    Posted 17 Mar 2010 Link to this post

    Hi There,

    I noticed that my images when inserted were using a relative path, so I added the MakeUrlsAbsolute content filter and that works fine. 

    But I need my hyperlinks to stay exactly how entered.  So <a href="[:token:]"> stays and does not become <a href="[:token:].

    Is this possible?
  2. Dobromir
    Dobromir avatar
    1633 posts

    Posted 18 Mar 2010 Link to this post

    Hi Dan,

    By design, the built-in content filter for paths is modifying A, AREA, EMBED and IMG tags and does not offer client side configuration. As a workaround I suggest you to create a custom content filter to fix the href attributes of A elements, e.g.:
    <telerik:RadEditor ID="RadEditor1" runat="server" ContentFilters="MakeUrlsAbsolute, DefaultFilters"
    <script type="text/javascript">
    function OnClientLoad(editor, args)
        editor.get_filtersManager().add(new MyFilter());
    MyFilter = function()
        this.set_name("RadEditor filter");
        this.set_description("RadEditor filter description");
    MyFilter.prototype =
        getHtmlContent: function(content)
            var regExp = new RegExp("<a[^>]*href=['\"][^>\"']*['\"][^>]*>", "gi");
            var newContent = content.replace(regExp, function(match, offset, fullText)
                return match.replace("http://" +, "");
            return newContent;
    MyFilter.registerClass('MyFilter', Telerik.Web.UI.Editor.Filter);

    Additional information regarding content filters is available in the following live demo:
    Custom Content Filters

    I hope this helps.

    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.
  3. DevCraft R3 2016 release webinar banner
  4. Kevin
    Kevin avatar
    15 posts
    Member since:
    Oct 2014

    Posted 31 Mar 2015 in reply to Dobromir Link to this post

    I am trying to use the code you have provided but I am running into an issue.  I am trying to make url paths absolute for images but not for hyperlinks.  I am trying to use the custom content filter you have provided here, but it wont remove the full url.  The url that is being added is like this:

    If is use the provided filter I will still get this added to all of my hyperlinks:

    If I change the replace to this:
    return match.replace("http://" + + window.location.pathname, "");
    it adds this to all my hyperlinks:

    If I change the replace to this:
    return match.replace("http://" + + window.location.pathname +, "");
    it doesn't replace any of it, it adds the full URL to all hyperlinks.

    I have tried several of things like:
    return match.replace(window.location.href, "");
    return match.replace(document.URL, "");
    and non of them work.  They will add the full URL to all hyperlinks.  What can I do to remove the full URL from being added to hyperlinks?

  5. Kevin
    Kevin avatar
    15 posts
    Member since:
    Oct 2014

    Posted 31 Mar 2015 in reply to Kevin Link to this post

    In doing some more research, I think the issue may be the regular expression.  Perhaps the fact that my URL has a ?.  It seems like I can't replace anything that comes after the ? which is where the search of my URL is.  Do I need to modify the regex to include question marks?
  6. Ianko
    Ianko avatar
    1507 posts

    Posted 01 Apr 2015 Link to this post

    Hello Kevin,

    The regex suggested catches all possible URL combination along with the query string, and I can only make guesses why it does not work on your end.

    What modification has been done to affect only images and not the hyperlinks? Maybe this difference is the one that leads to this behavior.


    See What's Next in App Development. Register for TelerikNEXT.

  7. Kevin
    Kevin avatar
    15 posts
    Member since:
    Oct 2014

    Posted 01 Apr 2015 in reply to Ianko Link to this post

    Hi Ianko,

    The issue is we want an absolute path to be added to images, so we set radEditor.ContentFilters = Telerik.Web.UI.EditorFilters.MakeUrlsAbsolute;  The problem is this is also putting an absolute path on hyperlinks, which we don't want.  We are passing hyperlinks in via merge fields, so the absolute path being added to the beginning of the merge fields was actually breaking our links.  So I created a custom content filter to remove the absolute path from the hyperlinks as per Dobromir's suggestion.  The problem I was running into is it wasn't removing the full absolute path that was being added.  I discovered the problem was the & in my url.  It was being changed to a &amp; in the html, so I had to update the match like so:
    var url = window.location.href;
            url = url.replace(/&/g, "&amp;");

    var newContent = content.replace(regExp, function (match, offset, fullText) {
                return match.replace(url, "");

    This fixed the issue.  So my issue is resolved.  Thanks again for the reply.
Back to Top
DevCraft R3 2016 release webinar banner