【问题标题】:Allow content documents (web pages) to detect my Firefox addon允许内容文档(网页)检测我的 Firefox 插件
【发布时间】:2011-07-02 16:11:47
【问题描述】:
在我的 Firefox 插件中,我正在寻找一种安全的方法来让内容代码检测插件本身的存在。
理想情况下,我想最终是允许内容代码通过执行来查询我的插件的存在:
if (window.navigator.my_addon) {
// the addon is present
} else {
// the addon is not present
}
任何建议/指针?
【问题讨论】:
标签:
javascript
firefox
dom
firefox-addon
【解决方案1】:
改编自 here(但使用 getter 将 my_addon 值设为只读)
// 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
);