Firefox extension opening a page on install

前端 未结 2 1703
借酒劲吻你
借酒劲吻你 2020-12-10 09:33

I noticed some Firefox extensions when installed will open up a page once you restart the browser, for example the StumbleUpon toolbar.

This is useful to show update

2条回答
  •  时光取名叫无心
    2020-12-10 09:59

    Though there might be a better way, I'm not aware of it... You can use the preferences system to track whether it's a first run/update

    Check if the preference exists, if not, open the page, create the pref with current extension version number. If the preference exists, check it against the current extension version number, if they are different, assume it's an update and open the page. (assuming you want the page opened every time it's updated as well)

    var prefs = Components.classes["@mozilla.org/preferences-service;1"]
                .getService(Components.interfaces.nsIPrefService);
    prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
    
    if ((prefs.getPrefType("extensions.yourextensionhere.yourprerference") == PREF_INVALID)
        || (prefs.getCharPref("extensions.yourextensionhere.yourprerference") != this.version)) {
        //open page and...
        prefs.setCharPref("extensions.yourextensionhere.yourprerference",this.version)
     }
    

    EDIT.. version check used == instead of != as it should have

提交回复
热议问题