由於在 Chrome, IE, Firefox, Opera 還有 Safari 都有一些 console 語法不盡相同,為了避免一執行到就掛點,建議可以在你的 js 中加上以下語法,這樣就不會遇到在程式中忘了移除 console.log,結果在 IE8 就直接死掉的問題了!!
(function() {
// Union of Chrome, Firefox, IE, Opera, and Safari console methods
var methods = ["assert", "cd", "clear", "count", "countReset",
"debug", "dir", "dirxml", "error", "exception", "group", "groupCollapsed",
"groupEnd", "info", "log", "markTimeline", "profile", "profileEnd",
"select", "table", "time", "timeEnd", "timeStamp", "timeline",
"timelineEnd", "trace", "warn"];
var length = methods.length;
var console = (window.console = window.console || {});
var method;
var noop = function() {};
while (length--) {
method = methods[length];
// define undefined methods as noops to prevent errors
if (!console[method])
console[method] = noop;
}
})();