UI Action script (client side) to save record & close the current window.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 05:50 AM
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();
Could anyone please help with the same?
Any response will be appreciated.
Thanks,
Ankita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 06:15 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 06:33 AM
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.
If my answer helped you in any way, please then mark it as helpful 🙂
MVP 2025 ✨