2

I have a function that removes hash from the URL using this code:

window.location.href = window.location.href.split('#')[0];

The function is triggered by either clicking a certain page element or by pressing the ESC key. Both work perfectly in Chrome, but in Firefox, the ESC key does not remove the hash, while pressing the page element does. I've tried other ways of removing the hash part, such as

location.href.replace(location.hash,"")

but with the same result. I know that the function IS triggered by the ESC key in FF, since other code inside it (such is hiding an overlay) executes successfully. Any ideas would be appreciated.

  • And you've seen this -> http://stackoverflow.com/questions/1397329/how-to-remove-the-hash-from-window-location-with-javascript-without-page-refresh – adeneo Dec 24 '15 at 11:56
  • Yes, but my question is not about refresh. Everything works perfectly using the code I've posted, except in Firefox, when triggering the hash removal function with ESC. – Victor Dubrovsky Dec 24 '15 at 12:17
  • So if you trigger it with another button, it works ? – adeneo Dec 24 '15 at 12:20
  • This code below removes the hash in FF, but once I scroll the mouse wheel, the hash is back: var scrollV, scrollH, loc = window.location; if ("pushState" in history) history.pushState("", document.title, loc.pathname + loc.search); else { scrollV = document.body.scrollTop; scrollH = document.body.scrollLeft; loc.hash = ""; document.body.scrollTop = scrollV; document.body.scrollLeft = scrollH; } – Victor Dubrovsky Dec 24 '15 at 12:37
  • Yes, when triggered with a page element that has an onmousedown event attached to it, the function works in both browsers. – Victor Dubrovsky Dec 24 '15 at 12:44
  • So it works with something other than the escape key, the issue surely is the escape key ? – adeneo Dec 24 '15 at 12:49
  • Not exactly: the escape key does execute the function, and the function does some work, but in Firefox it will not do the part of work that removes the hash. So the only combination when it doesn't work is: FF + using ESC + modifying hash – Victor Dubrovsky Dec 24 '15 at 12:57
  • That sounds like a strange bug, maybe you could find somewhere to post the issue on Mozilla's website, so they can look at it ? – adeneo Dec 24 '15 at 13:02
  • I'll try to, thanks for the suggestion. – Victor Dubrovsky Dec 24 '15 at 13:07
  • Did you find a solution for this? I encountered the same problem: Any change to `window.location` from an escape key handler seems to be ignored. – Daniel Rikowski May 12 '16 at 14:38
  • I wrote to the FF support team, and after testing in different environments, they couldn't replicate the bug. So I decided it was some bug in my local configuration. I haven't found a solution for this problem. – Victor Dubrovsky May 20 '16 at 13:03

0 Answers0