[英]How does Facebook log to console like this?
我和你一樣在檢查東西,在 facebook 上發現了這個有趣的東西。
我知道這完全可以用類似的東西來做:
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);
我的主要問題是,他們如何停止顯示您總是在控制台右側看到的 file.js:line_numer ?
使用上面的代碼,你會看到:
View Full Image
你注意到紅圈了嗎? 但在 facebooks 示例中,他們不顯示該信息。 我已經瀏覽了 Mozilla ( Link ) 上的 Web.Console API,那么有人可能知道如何排除特定的信息嗎?
你只需要異步/推遲console.log
調用,例如
setTimeout(console.log.bind(console, '%cFoo', 'color: #FF00FF;'), 0);
盡管我入黨晚了,但我認為這行!
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.