Question

Say a user visits the page http://somedomain.com/path/file.html#foo, I'd like to display, using JavaScript, somewhere on the page a text like:

 → foo
Was it helpful?

Solution

  1. Use window.location.hash to grab the anchor's name.

    var anchorName = window.location.hash;
    
  2. Create a text node to display what you want:

    var path = document.createTextNode("→ " + anchorName);
    
  3. Add it to the Dom:

    document.getElementById(idOfContainerYouWantToEdit).appendChild(path);
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top