2011-02-23 61 views
1

在我的Firefox插件中,我正在寻找一种安全的方式来让内容代码检测插件本身的存在。 理想是什么,我想用被允许内容代码通过执行查询我的插件存在落得:允许内容文档(网页)检测我的Firefox插件

if (window.navigator.my_addon) { 
    // the addon is present 
} else { 
    // the addon is not present 
} 

任何建议/指针?

+0

参见http://stackoverflow.com/questions/5067375/detecting-my-own-firefox-extension - 从-A-网页 – Neil 2011-02-23 20:28:03

回答

2

here改编(使用吸气,使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 
); 
相关问题