简体   繁体   中英

window.addEventListener(“load”, not working on page load

I am working on a simple firefox extension. I am stuck with an issue in which i need some help.

I want to add a style attribute in form element whenever page is loaded completely, so i am first trying with a simple alert.

So, i wrote some javascript code like,

var secureSession = function () {
    var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
    return {
        init : function () {
            gBrowser.addEventListener("load", function () {
                var autoRun = prefManager.getBoolPref("extensions.securesession.autorun");
                if (autoRun) {
                    alert("Hello World");
                }
            }, false);
        },
   };
}();

window.addEventListener("load", secureSession.init, false);

I set autorun -> ON, in preferences,

Now, the problem is it's not showing alert by default. means on page load.

It only showing me alert whenever i right click and click on inspect element.

Anyone has any idea about this.

Any help will be appreciated.

尝试gBrowser.addEventListener("DOMContentLoaded"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM