阻止使用firefox插件sdk API关闭标签 [英] Prevent the closing of a tab with firefox addon sdk API

查看:196
本文介绍了阻止使用firefox插件sdk API关闭标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法实现这个功能?

I am looking for a way to prevent the closing of a tab using the firefox addon sdk.

推荐答案

好的人在这里是你想要的。以前的版本是看我是否可以得到onbeforeunload触发只有当选项卡关闭,但我无法弄清楚。

解决方案

以下是如何做:
我们重写removeTab函数。遵循这些指导:



Here's how to do it: We override the removeTab function. Following the guidlines here: MDN :: Overriding/Extending/Amending existing functions - Alternative: Replace + Function.apply()

  // Keep a reference to the original function.
  var _original = gBrowser.removeTab;

  // Override a function.
  gBrowser.removeTab = function() {
    // Execute some action before the original function call.
    if (window.myAddonIsInstalled = true) {
        var closeit = confirm('are you sure you want to close the tab?')

        // Execute original function.
        if (closeit) {
            var rv = _original.apply(gBrowser, arguments);
        }

        // return the original result
        return rv;
    } else {
        var rv = _original.apply(gBrowser, arguments);
        // return the original result
        return rv;
    }
  };

在卸载您的插件时,请确保将window.myAddonIsInstalled的全局属性设置为false。因为这是建议您禁用每篇文章的功能的方法。

on uninstall of your addon make sure to set the global property of window.myAddonIsInstalled to false. As that is the recommended way to disable your functionality per that article.

这篇关于阻止使用firefox插件sdk API关闭标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆