使用JavaScript重定向网页

时间:2014-12-19 01:53:50   收藏:0   阅读:251

我们来看下下面两种方式:

1 // 等同于HTTP重定向
2 window.location.replace("http://baidu.com.com");
3 
4 // 等同于点击网页链接
5 window.location.href = "http://baidu.com";

 

window.location.replace(...) 模拟HTTP重定向的动作,对于window.location.href 来说,replace()并不保存在session中,这代表你无法使用浏览器的返回键来回到上一级页面,而如果你单纯地想模拟一个用户点击链接事件,那么使用location.href即可.

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!