jQuery加载没有被解雇

时间:2016-03-20 11:32:21

标签: javascript jquery html iframe load

拥有以下HTML页面(index.html)

.on("load")

以及以下iframe.html:

iframe.html

控制台输出如下所示:

document ready

然而,log" iframe已加载"不见了。似乎postMessage没有在iframe上被解雇。

有谁知道为什么?

修改

  • 当然我正在激活JavaScript(否则我不会看到任何日志消息)
  • 我无法修改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等不是我的解决方法
  • 我在最新的FF(47.0a2)和Chrome(49)
  • 中对此进行了测试

3 个答案:

答案 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>