====== formatplus jQuery 型別錯誤 ======
TypeError: jQuery.browser is undefined
if(jQuery.browser.msie && 8 > parseFloat(jQuery.browser.version)){
js.php?...3892c5d (line 59754)
* 原來是 jQuery 1.9 拿掉 jQuery.browser 了 ☞ [[https://stackoverflow.com/questions/24379212/typeerror-jquery-browser-is-undefined|javascript - TypeError: jQuery.browser is undefined - Stack Overflow]]
* ↑想改 /lib/plugin/formatplus/script.js,上文中提到應改用 navigation.userAgent,但我還是不得要領 :s\\ → 搜尋「replace jquery.browser」後找到 [[https://stackoverflow.com/questions/9645803/whats-the-replacement-for-browser#answer-15072522|jquery - What's the replacement for $.browser - Stack Overflow]] 裡有提供一段jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || [];
return {
browser: match[ 1 ] || "",
version: match[ 2 ] || "0"
};
};
if ( !jQuery.browser ) {
var
matched = jQuery.uaMatch( navigator.userAgent ),
browser = {};
if ( matched.browser ) {
browser[ matched.browser ] = true;
browser.version = matched.version;
}
// Chrome is Webkit, but Webkit is also Safari.
if ( browser.chrome ) {
browser.webkit = true;
} else if ( browser.webkit ) {
browser.safari = true;
}
jQuery.browser = browser;
}
→ 把這段程式碼插到該 script 的第 6 行後面(有先備份),再啟用 formatplus plugin\\ → 成功!瀏覽器 console 不會顯示 JavaScript 錯誤,formatplus 格式/^有效^/,再觀察看看有沒有影響 googleanalytics 的運作,確定沒有的話應該就好了!:D