Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.close() not working in firefox [duplicate]

I want to close current browser tab.

I have tried following

window.close();

and

  var win = window.open('', '_self');
  win.close();

But these are working fine in chrome but not working in firefox. I have researched also on google but I didn't find any solution.

I know these question is posted before but I have seen theme and I didn't find solution for this.


1 Answers

The first step is to fool the browser into thinking that it was opened with a script...

window.open('','_parent','');

This opens a new page, (non-existent), into a target frame/window, (_parent which of course is the window in which the script is executed), and defines parameters such as window size etc, (in this case none are defined as none are needed). Now that the browser thinks a script opened a page we can quickly close it in the standard way...

window.close();

In Mozilla by default the "dom.allow_scripts_to_close_windows" value which controls the Java Script close window is set to "false". In order to fix this issue change this value to "true"

  1. Location of the File:

    C:\Program Files\Mozilla Firefox\greprefs\all.js

change "dom.allow_scripts_to_close_windows" from "false" to "true"

Example:

Default value

pref("dom.allow_scripts_to_close_windows", false);

Change it to:

pref("dom.allow_scripts_to_close_windows", true);

2.Close Mozilla browser

3.Try accessing HTML page which has window.close() code snippet

like image 158
Dyrandz Famador Avatar answered Feb 24 '26 21:02

Dyrandz Famador



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!