使用window.close关闭窗口

时间:2015-04-03 20:36:52

标签: javascript jquery

我有两个页面(index.html和main.html)。这是index.html body标签:

<a href="main.html">main page</a>

在主页面上我有一个按钮,当点击该按钮时,我想关闭此窗口,但此功能不起作用!我怎么能这样做?并在控制台中发出此警告:

Scripts may close only the windows that were opened by it.

2 个答案:

答案 0 :(得分:0)

这应关闭窗口:

<form>
<input type="button" value="Close Window" onClick="window.close()">
</form>

答案 1 :(得分:0)

$('closeButton').click(function(){

  window.close();  //only if you opened the window, and are the owner will this work!  

});