window.open 用来打开新窗口
window.location 用来替换当前页,也就是重新定位当前页
用户不能改变document.location(因为这是当前显示文档的位置)。window.location本身也是一个对象。
但是,可以用window.location改变当前文档 (用其它文档取代当前文档),而document.location不是对象。
服务器重定向后有可能使document.url变动,但window.location.href指的永远是访问该网页时用的URL.
大多数情况下,document.location和location.href是相同的,但是,当存在服务器重定向时,document.location包含的是已经装载的URL,而location.href包含的则是原始请求的文档的URL.
判断当前浏览器是否是IE

<!--

function redirectClient(ieurl, nsurl) ...{
// test for Internet Explorer (any version)

if (navigator.userAgent.indexOf("MSIE") != -1) ...{
window.location = ieurl;

} else ...{

// it's not IE so assume it's Netscape
window.location = nsurl;
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
Click <A HREF="javascript:window.open('http://www.sina.com');void 0">here</A> 
Click <A HREF="javascript:redirectClient('http://www.sina.com',
'http://www.sohu.com')">here</A> 
to redirect based on the user's browser.
</BODY>
</HTML>
本文介绍了如何使用JavaScript中的window.open和window.location进行页面跳转,并提供了判断浏览器类型的方法。通过具体的HTML示例代码,展示了如何根据不同浏览器实现重定向。
1338

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



