Javascript 允许内容文档(网页)检测我的Firefox插件

Javascript 允许内容文档(网页)检测我的Firefox插件,javascript,firefox,dom,firefox-addon,Javascript,Firefox,Dom,Firefox Addon,在我的Firefox插件中,我正在寻找一种安全的方法,让内容代码检测插件本身的存在。 理想情况下,我希望最终通过执行以下命令来允许内容代码查询我的插件的存在: if (window.navigator.my_addon) { // the addon is present } else { // the addon is not present } 有任何建议/指针吗?改编自(但使用getter将my_加载项值设置为只读) 另见 // contentWindow is the wind

在我的Firefox插件中,我正在寻找一种安全的方法,让内容代码检测插件本身的存在。 理想情况下,我希望最终通过执行以下命令来允许内容代码查询我的插件的存在:

if (window.navigator.my_addon) {
  // the addon is present
} else {
  // the addon is not present
}
有任何建议/指针吗?

改编自(但使用getter将my_加载项值设置为只读)

另见
// contentWindow is the window object of a contentDocument being displayed
var s = new Components.utils.Sandbox(contentWindow);
s.window = contentWindow;
Components.utils.evalInSandbox("
  window.wrappedJSObject.navigator.__defineGetter__('my_addon', function(){ 
    return true; // or whatever we want its value to be
                 // (note: this is unprivileged code!)
  });", 
  s
);