0

I've tried quite a few versions of the window.close() method trying to get around the "Scripts may not close windows that were not opened by script." error and have settled on the code below. I no longer receive the scripts error, but all the below does is redirect to my index page of my single page app. Does anyone have any thoughts or ideas?

So I call it from this page (ng-click) /index.html#/complete

and it redirects me to /index.html#/

$window.open($window.location.pathname, '_self').$window.close();
Nick
  • 592
  • 6
  • 12
  • 21

1 Answers1

2
open(location, '_self').close();

is a workaround which you can use. The error you are getting on using that is:

Scripts may close only the windows that were opened by it.

Which is correct, you will not be allowed to close windows you didn't create.

See the full explanation here: window.close and self.close do not close the window in Chrome

Community
  • 1
  • 1
Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133
  • 1
    Thanks. For all curious I ended up using the following which closed IE without prompt. It did not work in Chrome as mentioned by Chankey above. open(location+'#/', '_self').close(); – Nick Oct 14 '14 at 15:28