js中的location的href和pathname,search版权声明
原创js中的location的href和pathname,search
在我们用来访问url,HTTP GET获取资源后。我们可以查看浏览器的location对象。
例如,我们search在浏览器中,将显示以下内容url:
使用window.location.href
结果是浏览器地址栏中的完整地址字符串:
“https://www.bing.com/search?q=location.href+location.pathname&go=%E6%8F%90%…ion.pathname&sc=0-14&sp=-1&sk=&ghc=1&cvid=be38977d2c4d483ba842e8019853315f”
window.location.pathname
得到URL路径的一部分(请求映射的地址)
“/search”
如果我们修改pathname浏览器中的地址栏url的pathname零件将更改并触发新的http get活动但下面的一长串参数仍然存在。
window.location.search
你得到的是:
“?q=location.href+location.pathname&go=%E6%8F%90%E4%BA%A4&qs=n&form=QBLH&pq=location.href+location.pathname&sc=0-14&sp=-1&sk=&ghc=1&cvid=be38977d2c4d483ba842e8019853315f”
其他:
window.location.host
“www.bing.com”
window.location.hostname
“www.bing.com”
window.location.port
“”
==== 说明: URL 端口部分
如果默认80端口(update:即使已添加:80)则返回值不是默认值80而不是空字符
本例中的返回值:”“
window.location.hash
如果使用锚点,例如。URL
http://localhost:8080/search?ver=1.0&id=6#herepointer
锚点 返回值:#herepointer
作者:whereismatrix
来源:CSDN
原文:https://blog.csdn.net/whereismatrix/article/details/47001267
版权声明:本文为博主原创文章,转载请附上博客链接!
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
itfan123



