Friday, July 18, 2008

How to avoid confirmation message when closing browser using window.close()

Description:
From javascript, when we use window.close() to close the browser window programmatically, Internet explorer shows a confirmation message.

Solution:
This solution does work for both IE 6 & 7.

Code snippet-start

Part 1:
function closeWindow(){
window.opener = ''; //Line 1
window.open('', '_self',''); // Line 2
window.close();
}

Part 2:
input value="Close Browser" onclick="closeWindow()" type="button"

Code snippet-end

Explanation:
Line 1 - is required for IE 6
Line 2 - is required for IE 7

No comments: