Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use the "targetObj" parameter to loadSubScript() in firefox extensions?
    primarykey
    data
    text
    <p>From reading examples, this seems like it should be quite easy. Here's my code:</p> <pre><code>rhkTest = { onPageLoad: function(event) { var doc = event.originalTarget; var wnd = doc.defaultView; var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"] .getService(Components.interfaces.mozIJSSubScriptLoader); loader.loadSubScript("chrome://rhkoshi-extension/content/testfoo.js", wnd); alert('typeof(wnd) = ' + typeof(wnd)); alert('typeof(wnd.window.rhk_test1) = ' + typeof(wnd.window.rhk_test1)); alert('typeof(wnd.window.rhk_test2) = ' + typeof(wnd.window.rhk_test2)); alert('typeof(wnd.window.rhk_test3) = ' + typeof(wnd.window.rhk_test3)); alert('typeof(wnd.rhk_test1) = ' + typeof(wnd.rhk_test1)); alert('typeof(wnd.rhk_test2) = ' + typeof(wnd.rhk_test2)); alert('typeof(wnd.rhk_test3) = ' + typeof(wnd.rhk_test3)); alert('typeof(rhk_test1) = ' + typeof(rhk_test1)); alert('typeof(rhk_test2) = ' + typeof(rhk_test2)); alert('typeof(rhk_test3) = ' + typeof(rhk_test3)); alert('typeof(this.rhk_test1) = ' + typeof(this.rhk_test1)); alert('typeof(this.rhk_test2) = ' + typeof(this.rhk_test2)); alert('typeof(this.rhk_test3) = ' + typeof(this.rhk_test3)); alert('typeof(window.rhk_test1) = ' + typeof(window.rhk_test1)); alert('typeof(window.rhk_test2) = ' + typeof(window.rhk_test2)); alert('typeof(window.rhk_test3) = ' + typeof(window.rhk_test3)); }, onLoad: function(event) { var appcontent = document.getElementById("appcontent"); if (appcontent) { appcontent.addEventListener("DOMContentLoaded", rhkTest.onPageLoad, true); } }, }; window.addEventListener("load", function(e) { rhkTest.onLoad(e); }, false); </code></pre> <p>where testfoo.js contains:</p> <pre><code>window.rhk_test1 = 'testval1'; rhk_test2 = 'testval2'; var rhk_test3 = 'testval3'; window.alert('Running testfoo.js'); </code></pre> <p>I get the alert "Running testfoo.js", so the file is found and executed. I also get an alert noting that wnd is an "object" (as expected -- it's initialized elsewhere). However, all the other alerts show "undefined" for the various typeof() calls. Naturally, I don't expect <em>all</em> of these to have values, but I was hoping that at least <em>one</em> of them might show something.</p> <p>What happened to my values? Aren't they supposed to be in properties of wnd?</p> <p>I'm running Firefox 19.0 on Windows 7 (if that matters).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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