避免 IE 抛出的常见习语:错误:'console' is undefined
- 作者: 沉睡的狮子
- 来源: 51数据库
- 2022-12-20
问题描述
我已经安装了 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 */ }
};
}
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0
