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

Summary

Closes the current window, or a referenced window.

Syntax

window.close();
  
  
  
  

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>
  
  
  
  

Closing the current window

<script type="text/javascript"> function closeCurrentWindow() { window.close(); } </script>

你可能感兴趣的:(window.close() doesn't work - Scripts may not close windows that were not opened by script.)