Firefox 扩展在安装时打开一个页面

发布于 2024-07-22 12:08:55 字数 245 浏览 12 评论 0原文

我注意到一些 Firefox 扩展安装后会在重新启动浏览器后打开一个页面,例如 StumbleUpon 工具栏

这对于显示更新说明并为用户提供一些教程类型信息非常有用。

当用户安装后第一次重新启动浏览器时,如何在 Firefox 插件中打开一个新页面?

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 notes and give the user some tutorial type information.

How do you go about opening a new page in a Firefox add-on the first time the user restarts the browser after install?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别在捏我脸啦 2024-07-29 12:08:55

虽然可能有更好的方法,但我不知道......
您可以使用首选项系统来跟踪是否是首次运行/更新

检查首选项是否存在,如果不存在,则打开页面,使用当前扩展版本号创建首选项。
如果首选项存在,请根据当前扩展版本号进行检查,如果不同,则假设它是更新并打开页面。 (假设您希望每次更新时都打开页面)

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)
 }

编辑..版本检查使用 == 而不是 != ,因为它应该有

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

风月客 2024-07-29 12:08:55

我没有直接使用 Firefox 扩展,但我想像在持久内存中存储标志(布尔值)一样(但是您存储用户首选项)。 当浏览器安装后第一次启动时,不会设置该标志,因此您显示帮助页面并设置该标志。 下次 Firefox 重新启动时,该标志已被设置,因此您无需打开帮助页面。

如果您希望每次更新扩展时都显示一个页面,请存储版本而不是布尔值,并在每次启动时检查当前版本是否大于存储的版本。

I have not worked directly with firefox extensions, but I would imagine something along the lines of storing a flag(boolean value) in persistent memory (however you store user preferences). When the browser starts the first time after the install, the flag would not be set, so you display the help page and set the flag. Next time firefox restarts, the flag will already have been set, so you don't open the help page.

If you wanted it to show a page every time the extension was updated, then store the version instead of a boolean, and on each startup check if the current version is greater than that of the stored one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文