Path problems with the rich text editor

19-12-2011
Informed Group notebook

Deze klanten gingen je al voor

The rich text editor within SharePoint will often cause some problems. Except the fact that the created HTML code isn’t always that neat, it is also nearly impossible to use relative paths in your links or images since it will always include the domain you’re currently on in your link. This of course is really annoying, especially when you have a separate domain for editing your content.

However, a workaround is possible which solves your problem. With the help of JavaScript it is possible to change the value of all links on your page. By making sure this piece of JavaScript is included on every page you will never have the problem of accidently creating dead links anymore.

JQuery is a very popular JavaScript framework which is already installed on a lot of sites. Most of the time it makes JavaScript scripting a lot easier and less time consuming. You can use the next piece of script to change all links and images so that the right domain name is being set.

[javascript]

if (document.domain == ‘www.publicurl.com’)
{
$("a[href^=’https://www.contenturl.com’%5D&quot😉 .each(function()
{
this.href = this.href.replace(/^https://www..contenturl.com/, "http://www.publicurl.com");
});
$("img[src^=’https://www.contenturl.com’%5D&quot😉 .each(function()
{
this.src = this.src.replace(/^https://www..contenturl.com/, "http://www.publicurl.com");
});
}
[/javascript]

In the first line:
if (document.domain == ‘www.publicurl.com’)
a check is being done to make sure we are on the public domain at the moment. You don’t want the links to be changed when you are editing the content.
Next, all links are being searched which contain the value “https://www.contenturl.com”. After that a function is begin executed which changes the href of the link from “https://www.contenturl.com” to “http://www.publicurl.com”.

Exactly the same is being done for all images on the site where the “src” of all the “img” tags are being altered.

If JQuery is not already installed and difficult to install it is also possible to use ‘normal’ javascript for this. In this case it isn’t even that much more work to write.

[javascript]

if (document.domain == ‘www.publicurl.com’)
{
for (i=0; i < document.links.length; i++)
{
document.links[i].href = document.links[i].href.replace("https://www.contenturl.com",";http://www.publicurl.com");
}
for (i=0; i < document.images.length; i++)
{
document.images[i].src = document.images[i].src.replace("https://www.contenturl.com","http://www.publicurl.com");
}
}
[/javascript]

This does exactly the same as the script above. It will find all links and images that contain “https://www.contenturl.com” and replaces this with “http://www.publicurl.com”.

Lees onze andere blogs

Deze website gebruikt cookies

Met deze cookies kunnen wij en derde partijen informatie over jou en jouw internetgedrag verzamelen, zowel binnen als buiten onze website. Op basis daarvan passen wij en derde partijen de website, onze communicatie en advertenties aan op jouw interesses en profiel. Meer informatie lees je in ons cookie statement.

Accepteren Afwijzen Meer opties

Deze website gebruikt cookies

Met deze cookies kunnen wij en derde partijen informatie over jou en jouw internetgedrag verzamelen, zowel binnen als buiten onze website. Op basis daarvan passen wij en derde partijen de website, onze communicatie en advertenties aan op jouw interesses en profiel. Meer informatie lees je in ons cookie statement.

Functionele cookies
Arrow down

Functionele cookies zijn essentieel voor het correct functioneren van onze website. Ze stellen ons in staat om basisfuncties zoals paginanavigatie en toegang tot beveiligde gebieden mogelijk te maken. Deze cookies verzamelen geen persoonlijke informatie en kunnen niet worden uitgeschakeld.

Analytische cookies
Arrow down

Analytische cookies helpen ons inzicht te krijgen in hoe bezoekers onze website gebruiken. We verzamelen geanonimiseerde gegevens over pagina-interacties en navigatie, waardoor we onze site voortdurend kunnen verbeteren.

Marketing cookies
Arrow down

Marketing cookies worden gebruikt om bezoekers te volgen wanneer ze verschillende websites bezoeken. Het doel is om relevante advertenties te vertonen aan de individuele gebruiker. Door deze cookies toe te staan, help je ons relevante inhoud en aanbiedingen aan je te vertonen.

Alles accepteren Opslaan

Ontdek onze QSEH Star