1

I can't close a chrome window with javascript. I've read it because it needs to also be opened with javascript, but there must be an easy way around this. What am I missing here?

<html>
    <head>
        <script>
        function close_window() {

            close();

        }
        </script>
    </head>
    <body>

    <a href="javascript:close_window();">close</a>
    </body>
</html>
user2242044
  • 7,943
  • 23
  • 91
  • 154
  • possible duplicate of [window.close and self.close do not close the window in Chrome](http://stackoverflow.com/questions/19761241/window-close-and-self-close-do-not-close-the-window-in-chrome) – Kritner Jan 30 '15 at 01:03

4 Answers4

4

You can't close a window you did not open, the browser won't let you do it for security reasons. There is no workaround.

Laurent Jalbert Simard
  • 5,429
  • 1
  • 23
  • 31
0

Nope, you can only close what you open with window.open...

Or if you kill the browser with a memory leak or something. (joke)

Shomz
  • 36,910
  • 3
  • 55
  • 83
0

See here. Use open() to open a new window, and close() to close the new window:

function openWin() {
    myWindow = window.open("", "myWindow", "width=200, height=100");    // Opens a new window
}

function closeWin() {
    myWindow.close();                                                  // Closes the new window
}
confile
  • 30,949
  • 47
  • 199
  • 357
0

In chrome it is not possible to close a webpage you did not open with javascript. It is possible however in some versions of firefox and internet explorer if that is an option for you.

 window.open('','_self').close();
Ian Thompson
  • 172
  • 1
  • 10