Add Styles to Console Statements
I was recently checking out Google Plus because they implement some awesome effects. I opened the console and same the following message:
WARNING!
Using this console may allow attackers to impersonate you and steal your information using an attack called Self-XSS.
Do not enter or paste code that you do not understand.
I wasn't surprised to see that message but what I did notice was that the text was red and the background was yellow. The text was even a bit bigger. How did they do it? Pretty easily:
console.log("%c%s",
"color: red; background: yellow; font-size: 24px;",
"WARNING!");
The first argument is the order of style and message, the second is the style set, and the last is the desired message.
As to why you'd want to use this? If it helps you identify debug information easier in the console, you may consider calling more attention to some messages!
![Regular Expressions for the Rest of Us]()
Sooner or later you'll run across a regular expression. With their cryptic syntax, confusing documentation and massive learning curve, most developers settle for copying and pasting them from StackOverflow and hoping they work. But what if you could decode regular expressions and harness their power? In...
![5 Ways that CSS and JavaScript Interact That You May Not Know About]()
CSS and JavaScript: the lines seemingly get blurred by each browser release. They have always done a very different job but in the end they are both front-end technologies so they need do need to work closely. We have our .js files and our .css, but...
![Introducing MooTools ScrollSidebar]()
How many times are you putting together a HTML navigation block or utility block of elements that you wish could be seen everywhere on a page? I've created a solution that will seamlessly allow you to do so: ScrollSidebar. ScrollSidebar allows you...
![Color Palette Generator Using jQuery]()
As I continue to learn jQuery, I think it's important that I begin by porting over scripts I've created using MooTools. One of those scripts is my Color Palette Generator script, which debuted on Eric Wendelin's blog. For those of you that...
Easy, if one controls the browser and therefor the console, that has to display this ;) But Firefox supports this as well, and only IE prints both, the format string as the string itself 1:1 into F12.
There’s a JS library that makes styling comments much easier:
https://github.com/astoilkov/console.message
By replacing your formatting placeholders with
%c%o
, it will output a readable repr for any type of object you pass in, not just the str value.https://jsfiddle.net/jsatt/Lta6p2jz/2/
very cool advice! my console is very colour ;)
With some trickery you can inject images too!
I find it amusing that this post starts with an example of a warning not to copy & paste code into the console, and ends with me wanting to copy & paste code from people’s comments into the console.
But it’s okay, cause I sort of understand it, right?
I like to put an object at the top of my script when I am developing to create a shortcut for styling my logs: