美文网首页
location对象表示当前页面的URL信息

location对象表示当前页面的URL信息

作者: zhao_ran | 来源:发表于2020-07-19 21:16 被阅读0次

例如,一个完整的URL:
http://www.example.com:8080/path/index.html?a=1&b=2#TOP
可以用location.href获取。要获得URL各个部分的值,可以这么写:

location.protocol; // 'http'
location.host; // 'www.example.com'
location.port; // '8080'
location.pathname; // '/path/index.html'
location.search; // '?a=1&b=2'
location.hash; // 'TOP'

相关文章

网友评论

      本文标题:location对象表示当前页面的URL信息

      本文链接:https://www.haomeiwen.com/subject/lairkktx.html