What Is the Difference Between "Window. Location. Href" and "Window. Location. Hash"?
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...
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?
6 Answers
For a URL like
hash- returns the part of the URL that follows the#symbol, including the#symbol. You can listen for thehashchangeevent to get notified of changes to the hash in supporting browsers.Returns: #testhref- returns the entire URL.Returns:
Read More
Test it on for example
href =
hash = #Page
href is the url
hash is only the anchor after the url
is the href
"#anchor" is the hash
The hash property returns the anchor portion of a URL, including the hash sign (#).
hash and href are both properties of the window.location object. hash is the part of the URL from the # on (or an empty string if there is no #), while href is a string representation of the whole URL.
Here is the simple example for difference between window.location.href and window.location.hash
For the URL :
- href:
- hash:
#!create