What is the difference between "window.location.href" and "window.location.hash"? What is the difference between "window.location.href" and "window.location.hash"? javascript javascript

What is the difference between "window.location.href" and "window.location.hash"?


For an URL like http://[www.example.com]:80/search?q=devmo#test

hash return the part of the URL that follows the # symbol, including the # symbol.You can listen for the hashchange event to get notified of changes to the hash in supporting browsers.

Returns: #test

href returns the entire URL.

Returns: http://[www.example.com]:80/search?q=devmo#test

Read More


Test it on for example http://stackoverflow.com/#Page

href = http://stackoverflow.com/#Page
hash = #Page


href is the url

hash is only the anchor after the url

http://www.xxxxxxx.com#anchor

http://www.xxxxxxx.com#anchor is the href

"#anchor" is the hash