javascript - window.postMessage 不工作 JavaScript
问题描述
我写了一个非常基本的代码,但它不起作用。请让我知道我的错误。谢谢你。
父方:
<!DOCTYPE html>
<html>
<head>
<title>Parent</title>
</head>
<body>
<script type="text/javascript">
window.onload = function() {
let el_win = window.open("https://www.example.com/child/", "_blank", "toolbar=no, scrollbars=no, resizable=no, top=0, left=0, width="+screen.availWidth+", height="+screen.availHeight);
el_win.focus();
el_win.postMessage("hello","*");
}
</script>
</body>
</html>
儿童侧:
<!DOCTYPE html>
<html>
<head>
<title>child</title>
</head>
<body>
<script type="text/javascript">
window.addEventListener("message", function(e) {
alert("Message Recieved");
console.log(e.data);
}, false);
</script>
</body>
</html>
Evenalert()
没有在子窗口中调用,也没有数据console.log()
解决方案
推荐阅读
- paypal - PayPal IPN 无法在 Kentico 版本 10 中使用沙盒帐户
- eclipse - Eclipse JBoss 混合移动工具 + cordovasim 显示已弃用
- python - Python - 欺骗库中的单个方法 - 处理死队列 - Djangoq/qcluster/SQS
- c# - 为监听器创建协程
- jquery - 为什么 jquery toggle() 在引导弹出窗口中不能以形式工作
- c - 如何在不尝试以读取模式打开的情况下轻松检查文件是否存在?
- ios - iOS Swift4如何检查字符串是否不为零且不为空?
- javascript - 通过 axios 导入 Vue 组件并更新内容
- c# - C# oledb 查询值和目标字段的个数不一样
- awk - awk if/else 抛出错误