方法的initCustomEvent传递数据不再工作 [英] initCustomEvent pass data for method doesn't work anymore
问题描述
我写了一个firefox扩展,并为特权和非特权页面之间的数据进行交互,我使用了这个剪切的代码
//听取事件
window.addEventListener(MyEvent,function(evt){
console.log(evt.detail);
},false);
//派发事件
var evt = document.createEvent(CustomEvent);
evt.initCustomEvent(MyEvent,true,true,{
name:'activate',
method:function(){
// ...
}
});
window.dispatchEvent(evt);
一切顺利后,我更新我的FireFox版本32.0.1,在这个时候我的FireFox doesn没有工作,我试图找到错误,发现我传递给MyEvent的方法总是为空。为什么?
有没有可能在新版本的FireFox中我无法再传递函数,或者我应该做一些更新的东西来解决我的问题?
您可能必须使用 __ exposedProps__ 。
$ b
var detail = {
name:activate,
method:function(){},
__exposedProps__:{method:r}
};不用说,除非你确定你知道你在做什么,否则这是有安全隐患。
I wrote a firefox extension and for interation data between privilege and non-privilege pages I use this snipped code
//Listen for the event
window.addEventListener("MyEvent", function(evt) {
console.log(evt.detail);
}, false);
//Dispatch an event
var evt = document.createEvent("CustomEvent");
evt.initCustomEvent("MyEvent", true, true, {
name : 'activate',
method : function() {
//...
}
});
window.dispatchEvent(evt);
and everything go well after I update my FireFox to version 32.0.1, at this time my FireFox doesn't work and I try to find the error and discover that the method I passed to MyEvent always null. Why?
Is it possible that in the new version of FireFox I couldn't pass function any more or I should do something newer for solve my problem?
解决方案 You probably have to use __exposedProps__.
Like
var detail = {
name: "activate",
method: function(){},
__exposedProps__: {method: "r"}
};
Needless to say that, unless you are absolutely sure that you know what you 're doing, this is a security risk.
这篇关于方法的initCustomEvent传递数据不再工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!