Javascript脚本:Location对象

 Location 对象是 Window 对象的一个部分,可通过 window.location 属性来访问。
举例说下 Location 对象 的属性与方法

hash:设置或返回从井号 (#) 开始的 URL(锚)
网址:http://www.csdn.net/index.html#head
返回:#head
<script type="text/javascript">
document.write(location.pathname);
</script>

host:设置或返回主机名和当前 URL 的端口号
网址:http://www.csdn.net:3389/index.html
返回:www.csdn.net:3389

hostname:设置或返回当前 URL 的主机名
网址:http://www.csdn.net:3389/index.html
返回:www.csdn.net

href:设置或返回完整的 URL
网址:http://www.csdn.net:3389/index.html
返回:http://www.csdn.net:3389/index.html

pathname:设置或返回当前 URL 的路径部分
网址:http://www.csdn.net/index.html#head
返回:/index.html

port:设置或返回当前 URL 的端口号
网址:http://www.csdn.net:3389/index.html
返回:3389

protocol:设置或返回当前 URL 的协议
网址:http://www.csdn.net:3389/index.html
返回:http:

search:设置或返回从问号 (?) 开始的 URL(查询部分)。
网址:http://www.csdn.net/index.html?id=333
返回:?id=333


assign():加载新的文档
语法:window.location.assign(URL)

reload():重新加载当前文档
语法:window.location.reload()

replace():用新的文档替换当前文档
语法:window.location.replace()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值