Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close browser tab and exit Angular2 application

I am working on an Angular2 application. In this application, I want to provide a button to the user which when clicked will close the application and the browser tab in which it was opened.

I tried searching for the solution but didn't find anything much on it. One approach suggested was to call onDestroy for all the components to prevent any memory leak. However I don't have much concrete to go forward.

like image 331
harsrawa Avatar asked Apr 19 '26 21:04

harsrawa


1 Answers

No you cannot as of now it is only possible in IE AFAIK and with chrome or firefox you will encounter error like this

app.component.ts:43 Scripts may close only the windows that were opened by it

You can look at this answer for more info https://security.stackexchange.com/questions/133744/why-do-browsers-disallow-script-closing-an-opener-window-yet-allow-changing-its

like image 77
Rahul Singh Avatar answered Apr 22 '26 16:04

Rahul Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!