简体   繁体   English

jQuery-在所有页面加载后执行附加脚本

[英]jQuery - appended script executed after all page loaded

I'm currently working on a page that have one iframe and one script adding a menu bar. 我目前正在处理一个具有一个iframe和一个添加菜单栏的脚本的页面。

The iframe have a script which is long to load, and the other script for the menu have to be add dynamically like this: iframe的脚本加载时间很长,必须动态添加菜单的其他脚本,如下所示:

jQuery(document).ready(function () {
    var script = document.createElement('script');

    var url = 'URL TO SCRIPT THAT ADD MENU BAR';
    script.type = 'text/javascript';
    script.src = url;
    jQuery("head").append(script);

});

After testing it seems that this code is executed but Chrome wait for the iframe to be completely loaded so the bar appears after few seconds when the iframe page has finished loading. 经过测试,似乎该代码已执行,但是Chrome等待iframe完全加载,因此在iframe页面完成加载后的几秒钟后,该栏就会出现。

So is there a way to execute the script appended before the script in the iframe? 那么,有没有一种方法可以执行iframe中脚本之前附加的脚本?

Thanks :) 谢谢 :)

HTML HTML

<iframe onload='load_script()'></iframe>

JS JS

        function load_script (){
            $.ajax({
                type: "GET",
                url: URL,
                dataType: "script"
            });
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM