开发者

Firefox Extension Execution Priority

I couldn't find it anywhere on Mozilla's documentation. Suppose I code an extension that uses addEventListener on keypress. What is the executi开发者_高级运维on priority if a webpage contains a JS code that calls addEventListener on keypress (or keydown) too? Is it guaranteed that my extension receives the event first?


The event first goes through a "capturing" phase, then a "bubbling" phase. If you use the capturing phase (by putting true as the last parameter to addEventListener) then your listener will get called before the one on the page, if the one on the page uses the bubbling phase. I guess if you don't know which way it works on the page, then you could just attach it to something out of reach of the page (like the browser object, or even gBrowser) and then you would be sure that yours goes first. See http://www.w3.org/TR/DOM-Level-3-Events/#event-flow

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜