在IE中写入脚本控制台(console.log)的正确方法是什么? [英] What's the correct way to write to the script console (console.log) in IE?

查看:410
本文介绍了在IE中写入脚本控制台(console.log)的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 console.log document.ready()中定义的替代品:

I have this substitute for console.log defined in document.ready():

$(document).ready(function(){
  console.log("doc ready");
  if(typeof console === "undefined"){
    console = { log: function() { } };
  }
}

我认为IE应该有这个函数可用,但是当我包括

I thought IE was supposed to have this function available but, when I include the call above

  console.log("doc ready");

Firefox控制台,但不是在IE中 - 事实上IE脚本执行完全断开了。

the output appears in the Firefox console but not in IE - in fact IE script execution breaks completely at this point.

在IE中写入控制台的正确方法是什么? / strong>

What's the correct way to write to the console in IE?

推荐答案

脚本执行因指令顺序错误而中断,可能会更好:

The script-execution breaks because of wrong order of the instructions, this may be better:

$(document).ready(function(){

  if(typeof console === "undefined"){
    console = { log: function() { } };
  }
  console.log("doc ready");
}

如果您先检查控制台是否存在不是),这会导致错误。

If you first access the console before checking if it exists(and creating it if not), this results into an error.

这篇关于在IE中写入脚本控制台(console.log)的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆