ThreeSixtyGiving / standard

The 360Giving data standard for UK philanthropic giving
http://www.threesixtygiving.org
Other
10 stars 15 forks source link

Redirecting urls with a # in them #212

Open caprenter opened 7 years ago

caprenter commented 7 years ago

It would be good if we could try to redirect some URLs with hashes in them. If we can't we can't, but it might be worth implementing a javascript sticking plaster?

Example URLs are: http://standard.threesixtygiving.org/en/latest/reference/#toc-grants-sheet should get us to http://standard.threesixtygiving.org/en/latest/reference/#grants-sheet

I think this code will sort of do it (but I have no idea where to put it in the code!):

<script type="text/javascript">

    var elem = (window.location.hash.replace('#toc-', ''); // look for old anchors starting #toc- and remove that bit
    elem.replace('#', '')); //because this also catches new anchors, we need to catch them.
        elem.scrollIntoView();

</script>

test links: http://standard.threesixtygiving.org/en/latest/reference/#toc-grants-sheet http://standard.threesixtygiving.org/en/latest/licensing/#toc-is-there-an-example-of-a-license-statement- http://standard.threesixtygiving.org/en/latest/identifiers/#toc-organisation-identifier http://standard.threesixtygiving.org/en/latest/identifiers/#toc-grant-identifier http://standard.threesixtygiving.org/en/latest/identifiers/#toc-why-identifiers-matter

idlemoor commented 7 years ago

scrollIntoView(true) is a bit better, it puts the element at the top of the screen