コードを含む test.html ページがあります ( https://gist.github.com/4293833 ):
<!doctype html>
<html>
<head>
<script>
var paymentEventHandler = function (e) {
console.log(e)
console.log('payment: ' + JSON.stringify(e.status))
alert('status: ' + e.status)
}
if (document.addEventListener) {
document.addEventListener('payment', paymentEventHandler)
} else {
document.attachEvent('onPayment', paymentEventHandler)
}
</script>
</head>
<body>
<iframe src='/iframe.html'></iframe>
</body>
</html>
および iframe.html:
<!doctype html>
<html>
<head>
<script>
var event
if (document.createEvent) {
event = document.createEvent("HTMLEvents")
event.initEvent("payment", true, true)
} else {
event = document.createEventObject()
event.eventType = 'payment'
}
event.status = 'ok'
if (window.parent.document.dispatchEvent) {
window.parent.document.dispatchEvent(event)
} else {
window.parent.document.fireEvent('onPayment', event)
}
</script>
</head>
<body>
</body>
</html>
コードは Chrome、Safari、Opera で動作しますが、Firefox ではundefined
. なんで?