jd.
jd.

Reputation: 10958

Disable JavaScript in a single Firefox tab

In a Firefox add-on built with the Add-on SDK, how can I disable and re-enable JavaScript for a single tab?

Upvotes: 5

Views: 3191

Answers (1)

Wladimir Palant
Wladimir Palant

Reputation: 57671

The SDK itself doesn't provide this functionality, you will have to work with the XUL directly. What you need to do is accessing the docShell property of the XUL <browser> element corresponding to the tab. The docshell has an allowJavascript property that lets you switch JavaScript on and off. Something like this should work:

var window = require("window-utils").activeBrowserWindow;
var tabBrowser = window.gBrowser;
var browser = tabBrowser.selectedBrowser;   // or: tabBrowser.browsers[n]
browser.docShell.allowJavascript = false;

Unfortunately, it doesn't seem possible to take a Tab object and find the corresponding XUL element - you have to work with the XUL window from the start.

Relevant documentation:

Upvotes: 5

Related Questions