views:

2548

answers:

2

I have a greasemonkey user script with this single line of code...

window.close();

but firefox does not allow a user script to close a window (as reported by an error message in the error console)

Is there a work around to this problem?

+4  A: 

You need to change configuration settings of Firefox (about:config) to allow this.

Steps:

  1. Go to address bar and type about:config
  2. Go to parameter dom.allow_scripts_to_close_windows
  3. Set its value as true

Now your script can close the TAB with 'window.close()'

eg.

function closeTab(){
    window.open('', '_self', '');
    window.close();
}
Mohit Nanda
But wont this allow *all* scripts to close windows? Is there a way way by which only greasemonkey scripts be allowed to close windows?
SDX2000
Since it is a Firefox config parameter, I dont think there is a way to add trusted script sources or something like that. If you allow a script to close a TAB, an Any script may close a tab.
Mohit Nanda
A: 

Since Firefox treats Greasemonkey code with the same privilages as the script code on external websites, it is not possible to only allow Greasemonkey code to be able to close the windows, but not regular scripts.

Tom