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

传送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"
}
原文地址:https://www.cnblogs.com/yi-mi-yangguang/p/6686099.html