console message JavaScript with green checkmark

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 07:28:58

问题


I was wondering if the was a possibility to have a green checkmark in your console just like console.warn has the yellow warning sign and console.error has the red error sign.

I have searched on the internet if there already was a function like that, but I couldn't find it. Now I'm looking for a way to put an icon before a console.log message.

Is this possible?


回答1:


Certainly is. You can use CSS in Chrome:

console.log("%c hi", "background: url(path/to/your/icon.png) 0 0 no-repeat; padding-left: 20px;");

From the documentation:

Dev Tools supports the following format specifiers:

%c Formats the output string according to CSS styles you provide.

Caveat:

The console doesn't support background-repeat for some odd reason. So you'd be better either adding some padding to your icon, or else moving the icon to the right-hand side:

console.log("hi %c", "background: url(path/to/your/icon.png) 0 0 no-repeat; padding-left: 20px;");


来源:https://stackoverflow.com/questions/22687459/console-message-javascript-with-green-checkmark

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!