How can I detect with javascript if an attribute "#" is appended to an url ?
I need a cross-browser solution. I'm currently using the following code, but it works only in Firefox:
if ((window.location.hash) || (window.location.hash != "#"))
window.scrollBy(0,-60);
thanks
First, there seems to be an error in your posted code. If you're going for the common string is neither null nor empty nor '#' pattern, it should be:
if (window.location.hash && window.location.hash != "#")
window.scrollBy(0,-60);
That said, since Location.hash is well-supported, the code above should work on all modern browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With