Is javascript window.location.hash defined?

Is there any way to determine if it is defined window.location.hash?

If it is set, I get the value of the variable and use it to display additional content on the page.

+3
source share
2 answers
if(window.location.hash) {
    // do stuff!
}
+12
source

What about:

if(window.location.hash !== '')
{
}

or

if(typeof window.location.hash !== 'undefined')
{
    //your code
}
+2
source

Source: https://habr.com/ru/post/1773427/


All Articles