Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

rewriteHashlinks


Go to End


2 Posts   2048 Views

Avatar
Nicolaas

Forum Moderator, 224 Posts

5 June 2007 at 11:14am

Hi Folk

rewriteHashlinks (part of the sapphire/core/SSviewer.php file), is really useful (it adds the current URL any links starting with # (internal links e.g. <a href="#top">go to the top</a>) , but unfortunately, it does not apply to the content (the data that is entered in the CMS by the admin) of the page itself. How would you recommend I go about implementing it in the content itself?

Any hints much appreciated.

Nicolaas

Avatar
Nicolaas

Forum Moderator, 224 Posts

5 June 2007 at 11:46am

Edited: 05/06/2007 11:47am

Hi

This is what I have written in JS to fix it....
var currentUrl = location.href;
var As = document.links;
for(i = 0; i < As.length; i++) {
var A = As;
if(A.href) {
var afterHash = A.href.split("#")[1]
if(afterHash) {
if(afterHash.length > 0) {
A.href = currentUrl + "#" + afterHash;
}
}
}
}