简体   繁体   中英

Jump to HTML anchor on another page without having #name

I have a website and want to link it to a particular anchor on another page.

The original way of doing this would be to <a href="/page#contact">Contact</a> The new page would then be http://website.com/page#contact

Is there a way to still link it to the anchor without having the url display as http://website.com/page#contact ?

Thank You

No. To do that, you'd have to be able to link to a page and force it to scroll without using a fragment ("#contact"), and there's no standard or common way to do that without code on the target page enabling it.

If you can write code for the target page, you could do this:

<script>
setTimeout(function() {
  var hash = location.hash.replace(/^#$/, '');
  if (hash) {
    location.hash = "";
  };
}, 0);
</script>

But again, you have to be able to put code on the target page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM