条件加载脚本使用Javascript IE问题

时间:2013-03-08 16:18:31

标签: javascript jquery internet-explorer

我将js(最终插件)动态加载到文档头部,除了ie之外工作正常。我正在使用JQuery.holdReady暂停直到我的加载完成。任何想法/答案都非常欢迎!

    //plugins url
    var pluginAUrl = "//bbtest1.swan.ac.uk/bbcswebdav/institution/jquery-lib/alertExample.js";
    var pluginBUrl = "//bbtest1.swan.ac.uk/bbcswebdav/institution/jquery-lib/pluginExample.js";

    //classes to determine load
    var pluginA_sel = "bb-rss";
    var pluginB_sel = "bb-slideshow";


    jQuery.noConflict();

    //pause doc ready
    jQuery.holdReady(true);
    console.log('hold and load plugins conditionally');


    //get classes
    var elem_A = document.getElementsByClassName(pluginA_sel);
    var elem_B = document.getElementsByClassName(pluginB_sel);

    //check if exists
    if(elem_A){
        var head= document.getElementsByTagName('head')[0];
        var script= document.createElement('script');
        script.type= 'text/javascript';
        script.src= pluginAUrl;
        head.appendChild(script);
        console.log('rss plugin');
    }


    if(elem_B){
        var head= document.getElementsByTagName('head')[0];
        var script= document.createElement('script');
        script.type= 'text/javascript';
        script.src= pluginBUrl;
        head.appendChild(script);
        console.log('slideshow plugin');
    }

    console.log('ok continue to doc ready!');

    //un pause doc ready!
    jQuery.holdReady(false);

    jQuery(document).ready(function($){
        console.log('doc ready, do funky things!');
    });

0 个答案:

没有答案