The CreatorCon Call for Content is officially open! Get started here.

UI Action script (client side) to save record & close the current window.

Ankita Kolhe
Tera Contributor

Hi Community,

 

I have a 'Save & Close' UI Action to save the record & close the current window.

However below code is not working:-

 

g_form.save();

window.close();

 

AnkitaKolhe_0-1698756596293.png

 

AnkitaKolhe_1-1698756629556.png

 

 

Could anyone please help with the same?

Any response will be appreciated.

 

Thanks,

Ankita

6 REPLIES 6

Hi @Isaac Vicentini ,

 

Thank yo so much for quick response.

However I have been told to implement this.

The code you shared is not working.

 

Thanks

Ordinary JavaScript cannot close windows willy-nilly. This is a security feature, to stop various malicious exploits and annoyances.
 

From the latest working spec for window.close():

The close() method on Window objects should, if all the following conditions are met, close the browsing context A:

  • The corresponding browsing context A is script-closable.
  • The browsing context of the incumbent script is familiar with the browsing context A.
  • The browsing context of the incumbent script is allowed to navigate the browsing context A.

A browsing context is script-closable if it is an auxiliary browsing context that was created by a script (as opposed to by an action of the user), or if it is a browsing context whose session history contains only one Document.

This means, with one small exception, JavaScript must not be allowed to close a window that was not opened by that same JavaScript.

 

Chrome allows that exception -- which it doesn't apply to userscripts -- however Firefox does not. The Firefox implementation flat out states:

This method is only allowed to be called for windows that were opened by a script using the window.open method.


If you try to use window.close() from a Greasemonkey / Tampermonkey / userscript you will get:

  • Firefox: The error message, "Scripts may not close windows that were not opened by script."
  • Chrome: just silently fails.

 

Reference: https://stackoverflow.com/questions/19761241/window-close-and-self-close-do-not-close-the-window-in-...

 

 

If my answer helped you in any way, please then mark it as helpful 🙂


Best regards,

Isaac Vicentini
MVP 2025


If my answer was helpful, mark it as Helpful or Accept as Solution.