拥有以下HTML页面(index.html)
.on("load")
以及以下iframe.html:
iframe.html
控制台输出如下所示:
然而,log" iframe已加载"不见了。似乎postMessage
没有在iframe上被解雇。
有谁知道为什么?
修改
Waiting for device.
Target device: lenovo-lenovo_a328-L7DEKZVWS8QSLV9T
Uploading file
local path:
C:\Users\vishal\AndroidStudioProjects\MyApplication3\app\build\outputs\apk\app-debug.apk
========================================================================
remote path:
/data/local/tmp/com.example.vishal.myapplication
------------------------------------------------
Installing com.example.vishal.myapplication
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.vishal.myapplication"
WARNING: linker: libvc1dec_sa.ca7.so has text relocations. This is wasting memory and is a security risk. Please fix.
WARNING: linker: libvc1dec_sa.ca7.so has text relocations. This is wasting memory and is a security risk. Please fix.
pkg: /data/local/tmp/com.example.vishal.myapplication Failure [INSTALL_FAILED_OLDER_SDK]
因此使用pkg: /data/local/tmp/com.example.vishal.myapplicationpath
等不是我的解决方法答案 0 :(得分:0)
检查浏览器中是否启用了javascript
修改强>
或尝试将index.html代码替换为:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Parent</title>
<script type="text/javascript">
function handleOnLoad(el) {
// el is the actual iframe
console.log("iframe loaded");
}
</script>
</head>
<body>
<iframe src="iframe.html" onload="handleOnLoad(this)"></iframe>
<script src="https://code.jquery.com/jquery-1.12.2.min.js"></script>
<script>
$(function(){
console.log("document ready");
$("iframe").on("load", function(){
// console.log("iframe loaded");
});
});
</script>
</body>
</html>
答案 1 :(得分:0)
守则运作良好。也许你为iframe提供的路径是错误的。检查它们是否在同一个文件夹中
答案 2 :(得分:-1)
您的代码<script src="https://code.jquery.com/jquery-1.12.2.min.js"></script>
<script>
$(function(){
console.log("document ready");
$("iframe").on("load", function(){
console.log("iframe loaded");
});
});
</script>
必须在iframe.html
中所以你的网页看起来就像修改后的。
的index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Parent</title>
</head>
<body>
<iframe src="iframe.html"></iframe>
</body>
</html>
Iframe.html的
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Child</title>
<script src="https://code.jquery.com/jquery-1.12.2.min.js"></script>
<script>
$(function(){
console.log("document ready");
$(window).on("load", function(){
console.log("iframe loaded");
});
});
</script>
</head>
<body>
<p>Lorem ipsum</p>
</body>
</html>