Nick
Nick

Reputation: 592

Close browser window in Angular SPA

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();

Upvotes: 0

Views: 14133

Answers (1)

Chankey Pathak
Chankey Pathak

Reputation: 21666

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

Upvotes: 2

Related Questions