javascript中获取浏览器的url

本文探讨了在不同浏览器中使用JavaScript获取当前页面URL的方法,并展示了在IE与其他现代浏览器(如Firefox、Opera、Google Chrome)中使用document.location、location.href等属性获取URL时存在的差异。

document.location

location.href(与location.toString()一样)

location

document.URL

 

在IE中document.URL与其它三个稍有不同

IE6~7(假设文件保存的桌面上,location.html)

<SCRIPT LANGUAGE="JavaScript">
<!--
	document.write(location.href);
	document.write("<br>");
	document.write(location);
	document.write("<br>");
	document.write(document.location);
	document.write("<br>");
	document.write(document.URL);
//-->
</SCRIPT>

 结果为:

file:///C:/Documents%20and%20Settings/Administrator/桌面/location.html
file:///C:/Documents%20and%20Settings/Administrator/桌面/location.html
file:///C:/Documents%20and%20Settings/Administrator/桌面/location.html
file://C:\Documents and Settings\Administrator\桌面\location.html

 

在firefox,Opera,Google中四个语句展示结果均相同

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值