PJAX listen to pjax:end event with standard js

匿名 (未验证) 提交于 2019-12-03 02:29:01

问题:

So github uses "defunkt's" PJAX module (https://github.com/defunkt/jquery-pjax#events), and I'm making a firefox addon that needs to listen to the event pjax:end

So far I can do it with jquery like this:

$(document).on('pjax:end', function (t) {    console.log('pjax:end'); }) 

however how do I do this with standard javascript functions?

document.addEventListener('pjax:end',function(){      console.log('ya'); }, true); 

does not work.

for those who know firefox-addons this code code does not work:

gBrowser.contentWindow.wrappedJSObject['$'](gBrowser.contentDocument).on('pjax:end', function (t) {     Cu.reportError('pjax:end'); }) 

it throws this error:

/* Exception: Permission denied to access property 'guid' te.event.add@https://github.global.ssl.fastly.net/assets/frameworks-752c70f2b89dcf2d1f948637afa35a3285fe6424.js:2 e.event.add@https://github.global.ssl.fastly.net/assets/frameworks-752c70f2b89dcf2d1f948637afa35a3285fe6424.js:3 .on/<@https://github.global.ssl.fastly.net/assets/frameworks-752c70f2b89dcf2d1f948637afa35a3285fe6424.js:2 .each@https://github.global.ssl.fastly.net/assets/frameworks-752c70f2b89dcf2d1f948637afa35a3285fe6424.js:1 te.prototype.each@https://github.global.ssl.fastly.net/assets/frameworks-752c70f2b89dcf2d1f948637afa35a3285fe6424.js:1 .on@https://github.global.ssl.fastly.net/assets/frameworks-752c70f2b89dcf2d1f948637afa35a3285fe6424.js:2 @Scratchpad/2:1 */ 

回答1:

As far as I'm aware its not currently possible to catch jQuery events using native JavaScript (although looking at this bug ticket http://bugs.jquery.com/ticket/11047 it appears that there are some library's that would enable this, but not without code changes to the PJAX code).



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!