Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

javascript - PJAX listen to pjax:end event with standard js

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
*/
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...