2011-02-23 46 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 
); 
相關問題