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?
One important difference is that
window.location.hash
is urldecoded, while the fragment identifier inwindow.location.href
is not urldecoded. In other words:If the URL is
http://example.com/page#3%3D3
then:In other words:
Test it on for example
http://stackoverflow.com/#Page
Here is the simple example for difference between
window.location.href
andwindow.location.hash
For the URL
http://www.manm.com/member/#!create
:http://www.manam.com/member/#!create
#!create
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
The hash property returns the anchor portion of a URL, including the hash sign (#).
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.
href returns the entire URL.
Read More