本文介紹了避免 IE 拋出的常見習語:錯誤:'console' is undefined的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我已經安裝了 firebug 并編寫了所有這些日志語句.
I've installed firebug and I wrote all these log statements.
我已經在 IE 中測試了我的應用程序,當然我遇到了未定義"錯誤.
I've tested my app in IE and of course I've got "undefined" error.
避免這種情況的常用習語是什么.
What's the common idiom to avoid this.
我真的不想評論我文件中的所有 console.log 語句,也不想模擬它們.
I don't really feel like commenting all the console.log statements in my file nor to mock them.
嗯,我不知道該怎么辦.
Well I'm not sure what to do.
推薦答案
我通常做一個這樣的包裝函數:
i usually make a wrapper function like so:
function log(obj) {
if (window.console && console.log) console.log(obj);
}
或者你可以在你的腳本文件/元素的開頭做這樣的事情:
or you could do something like this at the beginning of your script file/element:
if (!window.console) {
window.console = {
log: function(obj){ /* define own logging function here, or leave empty */ }
};
}
這篇關于避免 IE 拋出的常見習語:錯誤:'console' is undefined的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!