Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The javascript code in the overlay code doesn't work because it runs earlier than gbrowser contains any tabs.</p> <p>In Firefox (or Thunderbird) extensions you usually start your extension in a load event listener:</p> <pre><code>window.addEventListener("load", pinfresh.init, false); </code></pre> <p>The init function then needs to register event listeners for various tab events:</p> <pre><code> pub.init = function() { var container = gBrowser.tabContainer; container.addEventListener("TabOpen", tabOpened, false); container.addEventListener("TabClose", tabRemoved, false); }; </code></pre> <p>When a new tab is opened we register another listener which will trigger the tab reload when the user double clicks on the tab:</p> <pre><code> tabOpened = function(e) { var tab = e.target; tab.addEventListener("dblclick", tabDoubleClicked, false); } tabDoubleClicked = function(e) { gBrowser.reloadTab(e.target); } </code></pre> <p>The complete code looks like this: </p> <pre><code>&lt;overlay id="pinfresh" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt; &lt;script type="application/x-javascript"&gt; pinfresh = function() { var pub = {}; tabOpened = function(e) { var tab = e.target; tab.addEventListener("dblclick", tabDoubleClicked, false); } tabRemoved = function(e) { var tab = e.target; tab.removeEventListener("dblclick", tabDoubleClicked, false); } tabDoubleClicked = function(e) { gBrowser.reloadTab(e.target); } pub.init = function() { var container = gBrowser.tabContainer; container.addEventListener("TabOpen", tabOpened, false); container.addEventListener("TabClose", tabRemoved, false); }; return pub; }(); window.addEventListener("load", pinfresh.init, false); &lt;/script&gt; &lt;/overlay&gt; </code></pre> <p>For code snippets to work with tabs I recommend the <a href="https://developer.mozilla.org/en/Code_snippets/Tabbed_browser" rel="nofollow">Tab Browser</a> page at the Mozilla Development Center.</p> <p>I recommend putting the Javascript code in its own file instead of including it in the XUL file. Errors in external Javascript files show up in Firefox's error console which makes debugging a lot easier.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload