0
我有一个影子DOM的iFrame:的postMessage到iFrame的阴影DOM有event.source集最晚将event.target铬
<iframe id="output-frame" src="http://localhost:8080/external/output.html" data-src="http://localhost:8080/external/output.html" style="height: 570px; width: 322px;">
#document
<html>...</html>
</iframe>
我发个帖子消息吧:
postFrameOrigin: function postFrameOrigin() {
var match = /^.*:\/\/[^\/]*/.exec(this.$el.find("#output-frame").attr("data-src"));
return match ? match[0] : window.location.protocol + "//" + window.location.host;
},
postFrame: function postFrame(data) {
// Send the data to the frame using postMessage
this.$el.find("#output-frame")[0].contentWindow.postMessage(JSON.stringify(data), this.postFrameOrigin());
// Here `postMessage` is called ...
},
我接受它的影子DOM:
bind: function bind() {
// Handle messages coming in from the parent frame
window.addEventListener("message", this.handleMessage.bind(this), false);
// ... here `message` is received ...
},
handleMessage: function handleMessage(event) {
var data;
this.frameSource = event.source; // event.source contains target (falsly?)
this.frameOrigin = event.origin;
(...)
在Firefox和Chrome浏览器,直到版本52,我收到源对象正确在event.source
。从版本53开始,它包含目标对象,与event.target
或event.srcElement
中的相同。 (还有最近的歌剧,因为他们使用Blink)。闪烁切换到该版本的影子dom V1。它看起来像有一个连接。
这是一个错误?如果不是,那么我如何才能访问源对象呢?