hash link reloads page

2019-07-20 05:30发布

I have a code snippet that is installed on third party websites. I can't get into the details, but it loads HTML, CSS and JS onto the page through the use of a <script> tag.

Part of the code is a JS function that executes when this link is clicked:

<a href="#">?</a>

If there are JS errors on the page that prevent the function from executing, clicking the link obviously just adds the hash to the URL and takes the user to the top of the page. This is the expected fallback behavior.

However, on one third party site with a multitude of JS errors, clicking the link removes everything after the top level domain, adds the hash, and directs to that page (the home page). For example, the link would take the user from:

http://www.example.com/2010/05/14/very-interesting-blog-post/

to

http://www.example.com/#

Notably, the issue occurs in Firefox and Chrome, but not IE9. I know it may be impossible to properly diagnose the issue without more detailed code, but I'm not at liberty to provide it. I'm just hoping to get some kind of reasonable explanation for this strange browser behavior.

If it helps at all, the site in question is a WordPress blog. Thanks in advance.

EDIT: This is apparently not caused by any JS on the site, because turning off JS and adding the link with the inspector produced the same behavior.

1条回答
啃猪蹄的小仙女
2楼-- · 2019-07-20 05:59

I had a similar error where clicking on any <a href="#"> causes a full page reload. I managed to solve this by removing the <base href="/"> tag from the <head> of the page. I couldn't find any informations on this (yet). I'll add more if I can find any additional info.

查看更多
登录 后发表回答