- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有三个 url:
<html>
<body>
<iframe id="i1"></iframe>
<script>
var contentWindow = document.getElementById('i1').contentWindow;
var oScript = contentWindow.document.createElement('script');
oScript.src = "http://loader.com";
contentWindow.document.childNodes[0].childNodes[1].appendChild(oScript);
</script>
</body>
</html>
var oFrame = document.createElement("iframe");
oFrame.src = "http://www.sf.com";
oFrame.onload = function() {
oFrame.contentWindow.postMessage({ msg: 'hi'}, 'http://sf.com');
}
document.childNodes[0].childNodes[1].appendChild(oFrame);
<html>
<head>
<script>
window.addEventListener('message', function(event) {
document.getElementById('h4').innerHTML = event.origin;
});
</script>
</head>
<body>
<h4 id="h4"></h4>
</body>
</html>
现在在任何“普通”浏览器(edge/firefox/chrome)中加载 http://home.com - 链会将脚本从“http://loader.com”加载到一个 iframe 中,该 iframe 将加载另一个带有“http://sf.com”的 iframe,最后一个 iframe 将显示“http://home.com”作为事件来源。但是在 Internet Explorer 11 中,事件来源设置为“about:”。有没有办法解决这个特殊的怪癖?我还没有找到关于这个特殊怪癖的任何文档(引用:https://caniuse.com/#search=postMessage)
最佳答案
我自己做了个测试,重现了同样的问题。我也搜索了很多资料,但没有找到任何线索。我想如果使用两个 iframe 会导致问题。所以我只使用一个 iframe 进行了另一项测试,event.origin
可以在 IE 中获得正确的 url。我使用如下代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title></title>
</head>
<body id="i1">
<script>
var contentWindow = document.getElementById('i1').contentWindow;
var oScript = document.createElement('script');
oScript.src = "http://loader.com";
document.childNodes[1].childNodes[2].appendChild(oScript);
</script>
</body>
</html>
var oFrame = document.createElement("iframe");
oFrame.src = "http://sf.com";
oFrame.onload = function () {
oFrame.contentWindow.postMessage({ msg: 'hi' }, 'http://sf.com');
}
document.childNodes[1].childNodes[2].appendChild(oFrame);
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title></title>
<script>
window.addEventListener('message', function(event) {
document.getElementById('h4').innerHTML = event.origin;
});
</script>
</head>
<body>
<h4 id="h4"></h4>
</body>
</html>
虽然没有找到任何文档证明,但测试结果让我觉得在使用嵌入式 iframe 时,IE 可能存在一些限制。作为一种解决方法,您可以尝试仅使用一个 iframe。
关于javascript - IE11 中的 postMessage 处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58329823/
我正在掌握 Chrome 自定义选项卡中可用的功能,我很想知道如何在自定义选项卡和应用程序本身之间进行通信。我可以在 CustomTabsSession 中看到有类似 requestPostMessa
我正在创建 Cypress e2e 测试,但是我们的应用程序作为父页面顶部的模态 (iframe) 打开。由于 Cypress 不支持 iframe,我决定尝试“独立”运行应用程序。但是,在启动应用程
显然,使用 window.postMessage是 preferred way在所有现代浏览器中通过 window.setTimeout(fn, 0) 对异步 javascript 回调进行排队。我找
我有 2 个应用程序,一个是隐藏窗口(“hW”),另一个是控制台应用程序(“CA”),来自我想向硬件发送命令。在控制台应用程序中,我得到了硬件句柄,这是一个问题:如果我正在运行: PostMessag
所以我在 Html5 Demos 上摆弄 Html5 PostMessage 示例我创建了一个示例 jsfiddle看看我是否理解它是如何协同工作的。 该演示使用了 document.getEleme
我有一个包含 iFrame 的基本 HTML 页面。当父级加载并且 iFrame 在其中时,iFrame 执行以下 javascript: myParent = window.top; if (win
我有以下脚本 父页面(pair_pixel_filter.php): window.addEventListener("message", function(e) { $('
我遇到的问题是,在注册服务 worker 后,navigator.serviceWorker.controller 始终为 null。 我想使用 postMessage 向 service worke
我正在使用 window.postMessage 函数与 Angular Controller 通信 iframe https://developer.mozilla.org/en-US/docs/W
我在关注 this本地消息传递指南,但现在我陷入了停滞。 Firefox 上的开发者控制台不断给我同样的错误: “尝试在断开连接的端口上发布消息”以及之前的“Webconsole 上下文已更改”。 我
有一个问题我无法解决。我在 Delphi 中创建了两个服务应用程序并尝试在其中发布消息。当然,此类应用程序中没有窗口,PostMessage 需要一个窗口句柄参数来发送消息。 因此,我使用 Alloc
到目前为止,我只看到过关于 postmessage 的教程,其中一个窗口发送一种消息,而另一个窗口仅以一种方式解释消息。 如果我想在窗口之间进行许多不同类型的交互怎么办,postmessage 可以处
我有一个带有视频 API 的 HTML 5 简单表单,我想在用户单击提交按钮时播放视频 这里是演示 HTML 表单输入。 HTML 5
我不知道该怎么办。我尝试了来自不同来源的几个示例代码,我在不同的浏览器(从 Chrome 9 到 FF 4)中尝试了它们,但似乎仍然没有任何东西可以与“postMessage”功能一起使用。JS 控制
我正在尝试将消息从父窗口发布到它打开的子窗口。然而,该消息并未被发布。 在父窗口脚本中: function editAnnotation(annotKey){ var annotString
我正在使用 var handle = window.open(url, name, options) 创建一个弹出窗口。该窗口包含许多允许用户导航的链接。用户完成导航后,可以单击按钮来表示已完成。当用
我有一个包含表单的 iframe,在该 iframe 中我有以下内容: // Send a message to the parent window window.parent.postMessag
我正在尝试将消息从父窗口发布到它打开的子窗口。然而,该消息并未被发布。 在父窗口脚本中: function editAnnotation(annotKey){ var annotString
我正在尝试使用 Ben Almans jquery postmessage调整 iFrame 的大小。我或多或少地将他的示例与不同的服务器和动态内容一起使用。 我也在该网站上发布了一个问题,但这可能是
我正在尝试使用实验性 Canvas 功能 - offscreenCanvas。 index.html const canvas = document.queryS
我是一名优秀的程序员,十分优秀!