您当前的位置: 首页 >  Java

暂无认证

  • 0浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

JavaScript获取当前页面网址信息、路径、地址、网址、本页面、url、window、location、href、protocol、host、port、pathname、search、hash

发布时间:2022-05-18 18:32:56 ,浏览量:0

目录
  • 1、获取整个URL地址
  • 2、获取url协议
  • 3、获取url主机
  • 4、获取url端口
  • 5、获取url路径,文件地址
  • 6、获取url问号后面的部分
  • 7、获取url井号后面的分段
1、获取整个URL地址
console.log(window.location.href); // https://fanyi.baidu.com/translate?aldtype=16047&query=&keyfrom=baidu&smartresult=dict&lang=auto2zh#zh/en/%E5%B7%B2%E7%9F%A5 
2、获取url协议
console.log(window.location.protocol); // https: 
3、获取url主机
console.log(window.location.host); // fanyi.baidu.com 
4、获取url端口
console.log(window.location.port); // 返回空字符,如果采用默认的80端口, // 即使添加了80端口,那么返回值并不是默认的80而是空字符 
5、获取url路径,文件地址
console.log(window.location.pathname); // /translate 
6、获取url问号后面的部分
console.log(window.location.search); // ?aldtype=16047&query=&keyfrom=baidu&smartresult=dict&lang=auto2zh 
7、获取url井号后面的分段
console.log(window.location.hash); // #zh/en/%E5%B7%B2%E7%9F%A5 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.3448s