js 关闭页面(Scripts may close only the windows that were opened by it.)

时间:2017-04-09 20:17:50   收藏:0   阅读:928

传送http://blog.csdn.net/kuangfengbuyi/article/details/52052301

js关闭当前页面,当该页面不是其他页面打开的,而是直接输入url,

直接用window.close()无法关闭。

以下代码可以实现不同浏览器的关闭操作:

    function closewin(){  
        if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Chrome") !=-1) {  
            window.location.href="about:blank";  
            window.close();  
        } else {  
            window.opener = null;  
            window.open("", "_self");  
            window.close();  
        }  
    }  

 

location对象

function currLocation()
{
alert(window.location)
}
function newLocation()
{
window.location="/index.html"
}

 

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