您的位置:首页 > 运维架构

window.close() doesn't work - Scripts may not close windows that were not opened by script.

2014-11-21 17:38 495 查看


Summary

Closes the current window, or a referenced window.


Syntax

window.close();
[/code]


Description

When this method is called, the referenced window is closed.

This method is only allowed to be called for windows that were opened by a script using thewindow.open method.
If the window was not opened by a script, the following error appears in the JavaScript Console:
Scripts
 may not close windows that were not opened by script.


Examples


Closing a window opened with
window.open()

<script type="text/javascript">
//Global var to store a reference to the opened window
var openedWindow;

function openWindow()
{
  openedWindow = window.open('moreinfo.htm');
}
function closeOpenedWindow()
{
  openedWindow.close();
}
</script>
[/code]


Closing the current window

<script type="text/javascript">
function closeCurrentWindow()
{
  window.close();
}
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐