0

ウィジェットをロードして依存関係をロードするときに、次のコードを使用しています。ウィジェットが他のページにロードされているため、jQuery の競合が発生する可能性があるため、以下の方法を使用してそれを回避しています。(IE を除くすべてのブラウザで完璧に動作します)

function ScriptLoadHandler(load) {
    var self = this;
    self.loaded = false;
    self.load = function () {
        if (!self.loaded) {
            load();
            self.loaded = true;
        }
    };
}

function loadScript(scriptURL, afterLoad) {
    var newScript = document.createElement('script');
    newScript.src = scriptURL;
    newScript.type = 'text/javascript';
    document.getElementsByTagName('head')[0].appendChild(newScript);

    if (typeof afterLoad === "function") {
        afterLoad = new ScriptLoadHandler(afterLoad);
        newScript.onreadystatechange = afterLoad.load;
        newScript.onload = afterLoad.load;
    }
}

loadScript('http://code.jquery.com/jquery-1.8.3.js', function () {
    loadScript('http://code.jquery.com/ui/1.9.2/jquery-ui.js', function () {
            // Load all of our $ dependancies before calling noConflict
            js13 = jQuery.noConflict(true);
            main(); // this is the main application function
    });
});

ただし、IE では次のエラーが発生します。

SCRIPT5009: 'jQuery' is undefined 
jquery-ui.js, line 6 character 1

SCRIPT5009: 'jQuery' is undefined 
jquery.cookie.js, line 14 character 3

SCRIPT438: Object doesn't support property or method 'cookie' 
widgetTest.js, line 107 character 6

何か案は?

4

1 に答える 1

0

このページの下部にあるコードを参照してください

于 2013-05-24T21:42:01.610 に答える