js 关闭网页

<button  onclick="window.opener=null;window.open('', '_self');window.close()">关闭</button>

很简单的关闭本页面的方法,没有其他额外的提示:

window.opener=null; //返回对创建该窗口的 Window 对象的引用。
window.open('', '_self'); //方法用于打开一个新的浏览器窗口或查找一个已命名的窗口。
window.close() //用于关闭浏览器窗口。

_self是在本页面打开一个新页面的意思,可以参考看target的四种属性_prarent,_blank,_selft,_top

但是这样的代码在关闭非脚本打开的页面。在网上搜搜找找,又看到了另一种方法:

window.location.href=”about:blank”;
window.close();

猜你喜欢

转载自blog.csdn.net/wangdan_2013/article/details/79411958