ANS-0691 · SUITESCRIPT DEVELOPMENT

How to Close a Browser Window or Tab with JavaScript in Firefox?

Firefox's security policies prevent JavaScript from closing windows or tabs that were not originally opened by a script, requiring specific conditions for successful closure.

Short answer

Firefox's security model restricts JavaScript's window.close() function. A tab or window can only be closed via JavaScript if it was initially opened by a JavaScript command, such as window.open(). Attempts to close manually opened tabs with window.close() will fail due to these security measures.

Scenario

Users attempting to close a browser tab or window using JavaScript's window.close() function in Firefox may find that the operation fails. This issue typically arises when the target tab or window was not originally opened programmatically via JavaScript.

Solution

Firefox's security model dictates that a tab or window cannot be closed via JavaScript if it was not originally opened by a JavaScript command. This is a security measure to prevent scripts from closing user-initiated tabs or windows without consent. A tab or window can only be closed via JavaScript if it was initially opened by a JavaScript command.

To test this behavior:

  1. Open a tab in Firefox. In the URL bar, type the following and press Enter:

javascript
    javascript:window.close();//

This action will fail to close the tab or window.

  1. In a tab in Firefox, type the following in the URL bar and press Enter:

javascript
    javascript:window.open('_parent','http://www.google.com');

This will open a new tab. Navigate to that new tab and in its URL bar, type:

javascript
    javascript:window.close();

This action will successfully close the tab or window.

This demonstrates that Firefox will not permit a tab or window to be closed via JavaScript if that tab or window was not originally opened by JavaScript.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant