js中实现页面跳转的方法

<html>
<head>
<script language="javascript"><!--
    
    function old_page()
    {
        window.location = "http://www.baidu.com"
    }
    function replace()
    {
        window.location.replace("http://www.baidu.com")
    }
    function new_page()
    {
        window.open("http://www.baidu.com")
    }
// --></script>
</head>
<body>
<input type="button" onclick="new_page()" value="new_page"/>
<BR />
<input type="button" onclick="old_page()" value="old_page"/>
<BR />
<input type="button" onclick="replace()" value="replace"/>
</body>
window.location和window.open的区别

window.location = "http://www.baidu.com" 跳转后有后退功能

window.location.replace("http://www.baidu.com") 跳转后没有后退功能

window.open("http://www.baidu.com") 要新的窗口打开链接


本人亲自测试 :window.location.replace 例如Index 和Index2 页面,从Index 页面到Index2页面后在进行后退的时候 可以 把来自
Index2的的返回挡在Index2 页面,不返回Index 页面

转载自:https://blog.csdn.net/xia9527/article/details/7635054

猜你喜欢

转载自blog.csdn.net/milijiangjun/article/details/81033179