我有问题路过的JavaScript阵列的插件,这是我正在写在附加生成器 。
为了沟通我使用的事件,并发送一个数组的事件,但加载项(内容脚本)获取的对象,而不是一个数组。
这是事件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="application/x-javascript">
$(function() {
$(window).bind('Runner-PageEvent', function(event) {
console.log('PAGE: Reakcja na Runner-PageEvent na stronie');
});
$(window).bind('RunnerResult', function(event) {
console.log('PAGE: Result is ' + event.originalEvent.detail.Result);
//// PROBLEM!!!
console.log('PAGE: Should be array: ' + event.originalEvent.detail.array); // firebug shows object
});
$(window).bind('Runner-DetectCallback', function(event) {
console.log('PAGE: Reakcja na Runner-DetectCallback na stronie');
$('#browser-detection').text('Extension detected').css('background-color', 'green').css('color', 'white');
});
var event = new CustomEvent("Runner-Detect", {});
window.dispatchEvent(event);
console.log('PAGE: Runner-Detect sent');
});
function CallExtension() {
var event = new CustomEvent("Runner-PageEvent", { detail : {
a: "messageA",
b: "messageB",
c: "messageC",
d: "messageD",
arrayA: ["a", "b", "c", "d"],
arrayB: [0, "info", "info2", 3]
}});
window.dispatchEvent(event);
console.log('PAGE: CALL EXTENSION clicked');
}
</script>
</head>
<body>
<div id="browser-detection" style="background-color: red">No extension</div>
<br/>
Run extension: <button onclick="CallExtension()">Run!</button>
</body>
</html>
萤火显示我的事件与一个属性对象detail.tab
与四个项目阵列。
内容脚本接收对象e
,其中e.detail.tab
是一个对象(但应该是阵列)。
window.addEventListener(
'eventname',
function(e) {
// console.log(e.detail.tab.length); -> produce an error on console (Ctrl+Shift+J)
// console.log(e.detail.tab[0]); -> as above
for(var x in e.detail.tab){
console.log(x);
console.log(e.detail.tab[x]);
}
self.port.emit('SendToExtension', e.detail);
}
);
我不知道是否有与附加生成器或我做错了什么问题?
请帮忙!