What is the difference between “[removed].href” an

2019-03-10 16:00发布

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?

7条回答
欢心
2楼-- · 2019-03-10 16:29

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.

查看更多
登录 后发表回答