Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  169] [ 4]  / answers: 1 / hits: 102646  / 15 Years ago, fri, april 17, 2009, 12:00:00

I need to close the tab which displays my webpage, by the click of a button. But firefox does not allow to close the window by javascript as long as it is not opened by javascript.
If I set the value of dom.allow_scripts_to_close_windows to be true, then even normal window.close() works too. But that is not a good solution. :(



I tried the following workaround suggested in one of the forums:



<script language=javascript type=text/javascript>
function closeWindow() {
window.open('','_parent','');
window.close();
}
</script>


It is supposed to fool the browser into thinking that it was actually opened by javascript, but this does not work in Firefox 3.



Can anyone please suggest a workaround?


More From » firefox

 Answers
61
function closeWindow() {
netscape.security.PrivilegeManager.enablePrivilege(UniversalBrowserWrite);
alert(This will close the window);
window.open('','_self');
window.close();
}

closeWindow();

[#99690] Saturday, April 11, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dylondaytond

Total Points: 92
Total Questions: 88
Total Answers: 96

Location: China
Member since Fri, Jan 15, 2021
3 Years ago
dylondaytond questions
Tue, Jun 22, 21, 00:00, 3 Years ago
Thu, May 7, 20, 00:00, 4 Years ago
;