0
此代碼適用於Firefox和Chrome,但不適用於IE9。它甚至可以在IE9中的相同域中工作,但在其他域中失敗。控制檯向我展示了一個SCRIPT1002:語法錯誤。我將這段代碼放在一個jsp中,並使用我的控制器的{domain} /路徑將其加載到腳本標記中。書籤不能在IE9上工作
(
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
}
}());
寫它試圖檢查readyState的時候,你可能有一個跨域問題..你可能需要加載jQuery的盲目 – gezzuzz
我曾評論了整節。而且我仍然得到同樣的錯誤。第4行字符1是錯誤根據IE9的地方。 – parjun
嘗試刪除( function(){}());部分... – gezzuzz