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中四个语句展示结果均相同
本文探讨了在不同浏览器中使用JavaScript获取当前页面URL的方法,并展示了在IE与其他现代浏览器(如Firefox、Opera、Google Chrome)中使用document.location、location.href等属性获取URL时存在的差异。
562

被折叠的 条评论
为什么被折叠?



