How to listen to custom events on all windows, bubbling issue?

前端 未结 1 1299
生来不讨喜
生来不讨喜 2020-12-21 12:39

I\'m trying to listen to custom event \'peakAhBoo\' so I add the event listener to gBrowser and if no gBrowser is present then I add it to aD

1条回答
  •  Happy的楠姐
    2020-12-21 13:14

    ok, now i see what you mean, but according to MDN you need to use this:

    document.addEventListener("MyExtensionEvent", function(e) { myExtension.myListener(e); }, false, true);
    // The last value is a Mozilla-specific value to indicate untrusted content is allowed to trigger the event
    

    source: https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Interaction_between_privileged_and_non-privileged_pages

    I tested it and it works!

    web page:

    
    
    
        
        
    
    
    
        

    and in privileged code:

    function respondToCustomEvent_peakAhBoo(e){
        console.log('g: '+e.target);
    }
    
    gBrowser.addEventListener("peakAhBoo", respondToCustomEvent_peakAhBoo, false, true);
    

    0 讨论(0)
提交回复
热议问题