页面的URL分析----window.location.href

window.location是页面的位置对象
window.location.href是 location的一个属性值,并且它是location的默认属性。

window.location直接赋值一个url实际上就是对window.location.href赋值。

location对象除了有href属性外还有很多其他属性。

上个图更清晰:

从图上可以看出来每一部分的表示,举个例子

location.pathname -- 返回URL的域名后的部分。例如 https://www.baidu.com/xhtml/ 返回/xhtml/

原文地址:https://www.cnblogs.com/wangmaoling/p/6634886.html