简体   繁体   中英

Bookmarklet not working on IE9

This code works on Firefox and Chrome but not IE9. It even works on the same domain in IE9 but fails on other domains. Console shows me a SCRIPT1002 : Syntax Error. I have this code in a jsp and loading it into a script tag using {domain}/path from my controller.

   (
        function(){
           var v = "1.9.1";
           if (window.jQuery === undefined || window.jQuery.fn.jquery < v ) {
           var done = false;
         var script = document.createElement("script");
         script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
         script.onload = script.onreadystatechange = function(){
        if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
         done = true;
            initBookmarklet();
        }
        };      
        document.getElementsByTagName("head")[0].appendChild(script);   
            } else {
                initBookmarklet();
            } 


            function initBookmarklet(){
                //do stuff here
            }
        }());

try writing it like this

var v = "1.9.1";
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
    var done = false;
    var script = document.createElement("script");
    script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
    script.onload = script.onreadystatechange = function () {
        if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
            done = true;
            initBookmarklet();
        }
    };
    document.getElementsByTagName("head")[0].appendChild(script);
} else {
    initBookmarklet();
}


function initBookmarklet() {
    //do stuff here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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