问题
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).
来源:https://stackoverflow.com/questions/21720367/pjax-listen-to-pjaxend-event-with-standard-js