Close Current Window/Tab w/JavaScript Button

Mindwatering Incorporated

Author: Tripp W Black

Created: 12/05/2013 at 01:13 PM

 

Category:
Notes Developer Tips
JavaScript

Issue:
The window functions: window.close(); and close(); won't close a current browser window or tab if the page was launched as a normal link. This is a security feature which is by design. It protects one page from being affected by another tab/page.
So how do you close the current page besides the little "x" in the corner of the tab or window?

Solution 1:
One way to fix the issue is to spawn the page (assuming it's a pop-up type dialog page) with window.open(...);
This fixes the security limitation and close(); works again.

Solution 2:
If the page is not a pop-up dialog type of page and is a "normal" web page. This is far from ideal. The page could easily be displayed outside the pop-up paradigm especially via a web search engines results page.
The best work-around that I have used is to quickly open up anything in the current page via JavaScript and then close it.

In the JSHeader, enter the following function:
function closeMe() {
var win = window.open('','_self'); /* url = '' or 'about:blank' */
win.close();
}

In the button you have created, change the code from Formula to JavaScript / Common JavaScript. Enter the following function call:
closeMe();



previous page