2

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.

user793487
  • 151
  • 2
  • 5
  • Turn off all javascript and try it. – Wesley Murch Jun 20 '12 at 21:42
  • Thanks for the suggestion. I did so in both browsers, and the behavior remained the same. – user793487 Jun 20 '12 at 21:52
  • OK, well then you know it's nothing to do with javascript. I would remove those points from your post and re-tag "javascript" to "html". You can click [edit] to clarify your post. – Wesley Murch Jun 20 '12 at 22:28
  • If that link is never supposed to do anything if JavaScript is disabled, then why not use another element rather than a link? You'll want to set `tabindex=0` on it so folks who navigate with keyboard can still focus it. Or perhaps even better insert the link with JavaScript so users who have it disabled never see a link that does nothing. – steveax Jun 20 '12 at 22:58
  • Thanks to everyone for your helpful insight. I'll try the above and let you know. @WesleyMurch, I'll re-tag the post accordingly. – user793487 Jun 20 '12 at 23:38
  • UPDATE: We've updated the code so that the link no longer uses a hash, but a link to a site as a fallback. So the issue is resolved, but the question is still unanswered. @steveax, all of the code is inserted with JS, so the very few users browsing without it won't see any of it. The fallback is necessary for sites with JS _errors_. – user793487 Jun 21 '12 at 00:26

2 Answers2

4

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.

posixpascal
  • 3,031
  • 3
  • 25
  • 44
0

This problem happens when you use windows.onpopstate to handle back or forward buttons and load page using ajax. Try to solve your js code for handling history.