本文介绍了PJAX使用标准js监听pjax:end事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此github使用"defunkt"的PJAX模块( https://github.com/defunkt/jquery -pjax#events ),而我正在制作一个需要监听事件pjax:end

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

到目前为止,我可以使用jquery做到这一点:

So far I can do it with jquery like this:

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

但是我该如何使用标准的javascript函数呢?

however how do I do this with standard javascript functions?

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

不起作用.

对于那些了解firefox附加组件的人,此代码无效:

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');
})

它抛出此错误:

/*
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
*/

推荐答案

据我所知,当前尚无法使用本机JavaScript捕获jQuery事件(尽管查看此故障单 http://bugs.jquery.com/ticket/11047 似乎有一些库可以启用此功能,但并非没有代码更改为PJAX代码).

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

这篇关于PJAX使用标准js监听pjax:end事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 09:49