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
  • 8,803
  • 25
  • 97
  • 164
  • 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,949
  • 1
  • 28
  • 36
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
  • 37,421
  • 4
  • 57
  • 85
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
}
Michael
  • 32,527
  • 49
  • 210
  • 370
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
  • 187
  • 1
  • 10