[英]How does Facebook log to console like this?
I was inspecting stuff, as you do, and came across this interesting thing on facebook.我和你一样在检查东西,在 facebook 上发现了这个有趣的东西。
I understand that is completely do-able with something similar to this:我知道这完全可以用类似的东西来做:
var cssRule =
"color: rgb(249, 162, 34);" +
"font-size: 60px;" +
"font-weight: bold;" +
"text-shadow: 1px 1px 5px rgb(249, 162, 34);" +
"filter: dropshadow(color=rgb(249, 162, 34), offx=1, offy=1);";
console.log("%cHello World", cssRule);
My main question is, How do they stop the showing of the file.js:line_numer that you always get on the right hand side in console?我的主要问题是,他们如何停止显示您总是在控制台右侧看到的 file.js:line_numer ?
With the above code, you would see this:使用上面的代码,你会看到:
View Full Image
Do you notice the red circle?你注意到红圈了吗? But in facebooks example, they don't display that information.
但在 facebooks 示例中,他们不显示该信息。 I've looked through the Web.Console API on Mozilla ( Link ), so does anybody possibly know how to exclude that specific peice of information?
我已经浏览了 Mozilla ( Link ) 上的 Web.Console API,那么有人可能知道如何排除特定的信息吗?
你只需要异步/推迟console.log
调用,例如
setTimeout(console.log.bind(console, '%cFoo', 'color: #FF00FF;'), 0);
Even though I joined the party late but I think this will do!尽管我入党晚了,但我认为这行!
var cssRule =
"color: rgb(249, 162, 34);" +
"font-size: 30px;" +
"font-weight: bold;" +
"text-shadow: 1px 1px 5px rgb(249, 162, 34);" +
"filter: dropshadow(color=rgb(249, 162, 34), offx=1, offy=1);" setTimeout(console.log.bind(console, "%cHello World", cssRule), 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.