I learned "window.location.hash" new and tried in my jquery code instead of "window.location.href" and both of them gave same results.
Code is here :
window.location.href = ($(e.currentTarget).attr("href")); window.location.hash = ($(e.currentTarget).attr("href"));
What is the difference between them?
Window Location Href The window.location.href property returns the URL of the current page.
The Location Hash property in HTML is used to return the anchor part of a URL. It can also be used to set the anchor part of the URL. It returns the string which represents the anchor part of a URL including the hash '#' sign. Syntax: It returns the hash property.
window. location is read/write on all compliant browsers. document. location is read-only in Internet Explorer (at least), but read/write in Gecko-based browsers (Firefox, SeaMonkey).
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
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