弘帝企业智能建站系统交流平台

 找回密码
 立即注册
查看: 3120|回复: 1

【JS】对浏览器地址栏的各种取值集锦

[复制链接]
发表于 2017-10-15 22:27:15 | 显示全部楼层 |阅读模式
//得到http://www.domain.com/path/file.html
var url=window.location;

//得到/path/file.html
var url=window.location.pathname;

//得到/file.html
url.substr(url.lastIndexOf('/'))

//得到file.html
url.substr(url.lastIndexOf('/')+1)


【JS】获取地址栏相关的函数
http://wh.ac.cn/forum.php?mod=viewthread&tid=542&fromuid=1

回复

使用道具 举报

 楼主| 发表于 2017-10-15 22:29:07 | 显示全部楼层
1,设置或获取对象指定的文件名或路径。
alert(window.location.pathname)

2,设置或获取整个 URL 为字符串。
alert(window.location);
alert(window.location.href);

3,设置或获取与 URL 关联的端口号码。
alert(window.location.port)

4,设置或获取 URL 的协议部分。
alert(window.location.protocol)

5,设置或获取 href 属性中在井号“#”后面的分段。
alert(window.location.hash)

6,设置或获取 location 或 URL 的 hostname 和 port 号码。
alert(window.location.host)

7,设置或获取 href 属性中跟在问号后面的部分。
alert(window.location.search)

8,获取变量的值(截取等号后面的部分)
var url = window.location.search;
//    alert(url.length);
//    alert(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=')+1, url.length);

9,用来得到当前网页的域名
var domain = document.domain;
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|弘帝企业智能建站系统 ( 皖ICP备07503252号 )

GMT+8, 2024-4-29 09:55 , Processed in 0.073000 second(s), 25 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表