Window.close() does not work anymore

Dear guys,
Since some days/month, the command window.close() (from anvil.js) doesn’t work in our app anymore. In the console an error message is displayed: ‘Scripts may close only the windows that were opened by it’. The strange thing is that we made a test app, where everything works fine (same code when clicking on a button).

Here is the test clone app: Anvil | Login

We basically can not find out why everything works fine in the clone app, but in our own app the script strikes.

One additional point: In our app the window.close() works fine when testing it from the editor, however, when opening the app through an url, the above displayed error message occurs.

If anybody has an idea or solution, we would really appreciate it! Thanks!

Unfortunately, windows.close does not actually work like that. Basically, there is no way for you to programmatically close your own website. It can only be closed when the user decides to close the tab.

The reason why it works on the editor is that your app was opened using windows.open method in which case it could be closed.

My advice - just let the others decide if they want to close the website or not.

Thanks for your response!
In our case we develop our app for using it as a pwa - so we want to give users the possibility to close the pwa with a button inside the app, rather than closing it with the close-button, so the others can really decide if they want to close the website or not.
But now we think we need to make a certain workaround. Thanks for your help!

2 Likes