Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » rewriteHashlinks

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

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

Page: 1
Go to End
Author Topic: 1521 Views
  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    rewriteHashlinks Link to this post

    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

  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    Re: rewriteHashlinks Link to this post

    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;
    }
    }
    }
    }

    1521 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.