1
<script type="text/javascript" src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript">
window.close();
</script>

This code doesn't work in Chrome and Fireworks, but it works in IE. What goes wrong? I try it using my friend's Chrome, and it works.

Marko Popovic
  • 3,999
  • 3
  • 22
  • 37
Kelvin Foo
  • 111
  • 1
  • 4
  • 13
  • Do you open this window from JS side? – Justinas Apr 26 '16 at 09:26
  • You can close a window with JS only if you opened it with JS. If you try to close a window with Chrome console, for example, you get `Scripts may close only the windows that were opened by it.` – Seblor Apr 26 '16 at 09:27
  • 1
    Already answered: http://stackoverflow.com/questions/19761241/window-close-and-self-close-do-not-close-the-window-in-chrome – Moob Apr 26 '16 at 09:28
  • http://www.yournewdesigner.com/css-experiments/javascript-window-close-firefox.html maybe this will work – Wouter den Ouden Apr 26 '16 at 09:29

1 Answers1

3

This method is only allowed to be called for windows that were opened by a script using the window.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.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
koninos
  • 4,969
  • 5
  • 28
  • 47