[英]Can I compare the source window from postMessage to my window.frames?
我想将框架中的一些信息冒泡到其父 object(由于 XSS 而无法访问的信息)。
我可以将通过postMessage
发送的source
window 与window.frames
的值进行比较吗?
MDN(在上面的链接中)说该消息可用于postMessage
回,但不涉及相等性测试。
这在 IE9 FF5 和 Chrome12 上正常工作,但我想知道这是否可靠(即它是否符合标准)。
测试代码:
postMessageOuter.html
<!DOCTYPE html>
<html>
<head>
<title>Outer Page</title>
<script type="text/javascript">
window.addEventListener("message", function (event) {
for (var i = 0; i < frames.length; ++i)
if (event.source == frames[i])
alert(i);
}, false);
</script>
</head>
<body>
<iframe src="postMessageInner.html"></iframe>
<iframe src="postMessageInner.html"></iframe>
<iframe src="postMessageInner.html"></iframe>
</body>
</html>
postMessageInner.html
<!DOCTYPE html>
<html>
<head>
<title>Inner Page</title>
<script type="text/javascript">
function foo() {
window.parent.postMessage("Hello", "*");
}
</script>
</head>
<body>
<input type="button" value="X" onclick="foo()" />
</body>
</html>
postMessage
是HTML5
草案的一部分,因此在最新的浏览器中得到支持。
规范说
source 属性必须设置为脚本的全局对象的 WindowProxy object
这个 WindowProxy 也是 window.frame 枚举的值。
http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.