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="www.mydomain.com/editor/[:token:].
Is this possible?
5 Answers, 1 is accepted
0
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.:
Additional information regarding content filters is available in the following live demo:
Custom Content Filters
I hope this helps.
Greetings,
Dobromir
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.
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"
OnClientLoad
=
"OnClientLoad"
>
</
telerik:RadEditor
>
<
script
type
=
"text/javascript"
>
function OnClientLoad(editor, args)
{
editor.get_filtersManager().add(new MyFilter());
}
MyFilter = function()
{
MyFilter.initializeBase(this);
this.set_isDom(false);
this.set_enabled(true);
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://" + window.location.host, "");
});
return newContent;
}
}
MyFilter.registerClass('MyFilter', Telerik.Web.UI.Editor.Filter);
</
script
>
Additional information regarding content filters is available in the following live demo:
Custom Content Filters
I hope this helps.
Greetings,
Dobromir
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

Kevin
Top achievements
Rank 1
answered on 31 Mar 2015, 04:25 PM
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:
myurl/trunk/default.aspx?page=3420&templateid=1014
If is use the provided filter I will still get this added to all of my hyperlinks:
/trunk/default.aspx?page=3420&templateid=1014
If I change the replace to this:
return match.replace("http://" + window.location.host + window.location.pathname, "");
it adds this to all my hyperlinks:
?page=3420&templateid=1014
If I change the replace to this:
return match.replace("http://" + window.location.host + window.location.pathname + window.location.search, "");
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?
myurl/trunk/default.aspx?page=3420&templateid=1014
If is use the provided filter I will still get this added to all of my hyperlinks:
/trunk/default.aspx?page=3420&templateid=1014
If I change the replace to this:
return match.replace("http://" + window.location.host + window.location.pathname, "");
it adds this to all my hyperlinks:
?page=3420&templateid=1014
If I change the replace to this:
return match.replace("http://" + window.location.host + window.location.pathname + window.location.search, "");
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?
0

Kevin
Top achievements
Rank 1
answered on 31 Mar 2015, 10:44 PM
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?
0
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.
Regards,
Ianko
Telerik
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.
Regards,
Ianko
Telerik
See What's Next in App Development. Register for TelerikNEXT.
0

Kevin
Top achievements
Rank 1
answered on 01 Apr 2015, 07:36 PM
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 & in the html, so I had to update the match like so:
var url = window.location.href;
url = url.replace(/&/g, "&");
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.
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 & in the html, so I had to update the match like so:
var url = window.location.href;
url = url.replace(/&/g, "&");
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.