[英]Javascript event custom property disappears
I have an iFrame inside my document, which at one point triggers a custom event: 我的文档中有一个iFrame,有一次它触发了一个自定义事件:
function notifyEnd(gameStatus) {
var fireOnThis = parent.document;
var evObj = document.createEvent('Event');
evObj.gameStatus = gameStatus;
evObj.initEvent('gameEnd', true, true);
fireOnThis.dispatchEvent(evObj);
}
Please note the gameStatus property set on the event. 请注意在事件上设置的gameStatus属性。
My document registers an event listener for this event: 我的文档为此事件注册了一个事件侦听器:
document.addEventListener('gameEnd', function(e) {
document.getElementById("gameEndForm:gameStatus").value = e.gameStatus;
document.getElementById("gameEndForm:gameCompleteButton").click();
}, true);
However, when the event is fired, the "gameStatus" property has an "undefined" value. 但是,触发事件时,“ gameStatus”属性具有“未定义”值。 I couldn't find any clue as to what could cause such a behaviour.
对于导致这种行为的原因,我找不到任何线索。
Thanks for your help, 谢谢你的帮助,
Sébastien 塞巴斯蒂安
Seems to me that you want to use a MessageEvent and use the data parameter of initMessageEvent. 在我看来,您想使用MessageEvent并使用initMessageEvent的data参数。
http://help.dottoro.com/ljknkjqd.php http://help.dottoro.com/ljknkjqd.php
You can use JSON is you want to pass more than just one string. 如果要传递多个字符串,可以使用JSON。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.