javascript console.log() 在 Safari 6.0 Web Inspector 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12015540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 15:04:56  来源:igfitidea点击:

console.log() doesn't work in Safari 6.0 Web Inspector

javascriptsafari6

提问by mko

console.log('hi');

undefined

Is there any similar implementation in 6.0? or Did I do something wrong?

6.0 中是否有类似的实现?或者我做错了什么?

回答by mko

I found the problem! Logs don't appear in the interactive console (which is located on the bottom), but in the Current Log window instead! You can access it through Develop > Show Error Consoleor the rightmost source icon in the Web Inspector.

我发现了问题!日志不会出现在交互式控制台(位于底部)中,而是出现在“当前日志”窗口中!您可以通过Develop > Show Error Console或 Web Inspector 中最右侧的源图标访问它。

So strange! Is it that hard to get simple output in the console, like putsand printin Ruby?

这么奇怪!在控制台中获得简单的输出是不是很难,比如RubyputsprintRuby?

回答by Marquizzo

Make sure that you're selecting "All" at the top of your console window. Sometimes it'll automatically switch to only show Errors, Warnings, or Logs. If you select "All", then you should see all your console.log()s!

确保您选择了控制台窗口顶部的“全部”。有时它会自动切换到仅显示错误、警告或日志。如果您选择“全部”,那么您应该会看到所有的console.log()s!

enter image description here

在此处输入图片说明

回答by dano

I have to develop "for Safari" as my primary target, but because Chrome and Safari both use WebKit as their engine, they are ALMOST identical in execution (one difference is the Safari parses date strings to Date worse).

我必须开发“for Safari”作为我的主要目标,但是因为 Chrome 和 Safari 都使用 WebKit 作为它们的引擎,所以它们在执行上几乎完全相同(一个区别是 Safari 将日期字符串解析为更糟糕的日期)。

So debugging and developing in Chrome is generally good enough as long as you do a final sanity check in Safari before checking in your code.

因此,只要您在检入代码之前在 Safari 中进行最后的健全性检查,在 Chrome 中进行调试和开发通常就足够了。

That being said, I wrote a console wrapper that gives me the ability to call console.login any browser... if it supports console.log, then it just works... otherwise it logs the message in an array that can be inspected.

话虽如此,我编写了一个控制台包装器,它使我能够console.log在任何浏览器中调用...如果它支持 console.log,那么它就可以工作...否则它会将消息记录在可以检查的数组中。

//======================================================//
// multi browser compatibility - not all support console
//======================================================//
var dummyConsole = [];
var console = console || {};
if (!console.log) {
    console.log = function (message) {
        dummyConsole.push(message);
    }
}

回答by roasty

Not preferred but it works.

不是首选,但它有效。

console.error(message);

console.error(message);

Note: I was running gulp serve -d -wwhich includes a watch. Even then I couldn't see the messages until I restarted gulp.

注意:我正在跑步gulp serve -d -w,其中包括一块手表。即便如此,在我重新启动 gulp 之前,我还是看不到这些消息。

回答by mbokil

If you are using JQuery what I do is dynamically add an ouput field to the page so I can see JavaScript values. The z-index is to keep it on the top. Style it however you want. I usually add a colored border or bright background color so it is easy to find on screen.

如果您使用的是 JQuery,我所做的就是向页面动态添加一个输出字段,以便我可以看到 JavaScript 值。z-index 是将其保持在顶部。随心所欲地设计它。我通常添加彩色边框或明亮的背景色,以便在屏幕上很容易找到。

var output= 'hello';
$('body').append("<div style='width:50px;z-index:1000'>" + output + "</div>");