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
有帮助吗?

解决方案

  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);
    
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top