Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

javascript - IE8中console.log发生了什么?(What happened to console.log in IE8?)

根据这篇文章,它在beta中,但是不在发行版中吗?

  ask by leeand00 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

console.log is only available after you have opened the Developer Tools (F12 to toggle it open and closed).

(console.log仅在打开开发人员工具(F12可以将其切换为打开和关闭)后可用。)

Funny thing is that after you've opened it, you can close it, then still post to it via console.log calls, and those will be seen when you reopen it.

(有趣的是,在打开它之后,您可以将其关闭,然后仍然通过console.log调用发布到它,并且在您重新打开它们时会看到它们。)

I'm thinking that is a bug of sorts, and may be fixed, but we shall see.

(我认为这是种错误,可能已修复,但我们会看到。)

I'll probably just use something like this:

(我可能只会使用这样的东西:)

function trace(s) {
  if ('console' in self && 'log' in console) console.log(s)
  // the line below you might want to comment out, so it dies silent
  // but nice for seeing when the console is available or not.
  else alert(s)
}

and even simpler:

(甚至更简单:)

function trace(s) {
  try { console.log(s) } catch (e) { alert(s) }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...