Styling Chrome's console.log

Recently I read from a blog that console.log can log text with specific styles.

By using "%c" you can indicate that the text should be styled using corresponding styles.

And you can use multiple "%c"s at the same time.

For example, If run the script below, you will have the following result.

console.log(‘%cfancy style! %canother example! ‘, ‘background: #222; color: #bada55; border-radius:5px‘,‘background: #222; color: #c4dbf2; border-radius:5px‘);

It first comes as,"woooooooooooooo", amazing!!  But then, I was like "of course it should be", because the whole dev tool should be built on html and css, logging with styles is like creating new DIV with styles, nothing hard to implement.

Then I tried the same trick on IE Edge, this feature is not implemented yet, it just concatenates all strings and logs them altogether.

So you will have following from your IE.

"%cfancy style! %canother example!  background: #222; color: #bada55; border-radius:5px background: #222; color: #c4dbf2; border-radius:5px"

Styling Chrome's console.log

时间: 2024-08-11 12:46:20

Styling Chrome's console.log的相关文章

前端不为人知的一面--前端冷知识集锦 前端已经被玩儿坏了!像console.log()可以向控制台输出图片

前端已经被玩儿坏了!像console.log()可以向控制台输出图片等炫酷的玩意已经不是什么新闻了,像用||操作符给变量赋默认值也是人尽皆知的旧闻了,今天看到Quora上一个帖子,瞬间又GET了好多前端技能,一些属于技巧,一些则是闻所未闻的冷知识,一时间还消化不过来.现分类整理出来分享给大家,也补充了一些平时的积累和扩展了一些内容. HTML篇 浏览器地址栏运行JavaScript代码 这个很多人应该还是知道的,在浏览器地址栏可以直接运行JavaScript代码,做法是以javascript:开

Chrome 中的console.log 之异步或者同步

以下结果只是我在chrome里面做的实验 图1 从图1可以看出  先执行console.log 打印出b 后才执行b.b=2; 然而事实是这样的吗? 图2 是否觉得跟图1得出的结论相悖论? 从结果推测执行顺序是 console.log a.a.a1.a2.a3=3; 后才打印a

【转】console.log 用法

转自http://www.cnblogs.com/ctriphire/p/4116207.html 大家都有用过各种类型的浏览器,每种浏览器都有自己的特色,本人拙见,在我用过的浏览器当中,我是最喜欢Chrome的,因为它对于调试脚本及前端设计调试都有它比其它浏览器有过之而无不及的地方.可能大家对console.log会有一定的了解,心里难免会想调试的时候用alert不就行了,干嘛还要用console.log这么一长串的字符串来替代alert输出信息呢,下面我就介绍一些调试的入门技巧,让你爱上co

Chrome 控制台console的用法(转)

下面我们来看看console里面具体提供了哪些方法可以供我们平时调试时使用. 目前控制台方法和属性有: ["$$", "$x", "dir", "dirxml", "keys", "values", "profile", "profileEnd", "monitorEvents", "unmonitorEvents&q

Chrome 控制台console的用法

原文出处: ctriphire 大家都有用过各种类型的浏览器,每种浏览器都有自己的特色,本人拙见,在我用过的浏览器当中,我是最喜欢Chrome的,因为它对于调试脚本及前端设计调试都有它比其它浏览器有过之而无不及的地方.可能大家对console.log会有一定的了解,心里难免会想调试的时候用alert不就行了,干嘛还要用console.log这么一长串的字符串来替代alert输出信息呢,下面我就介绍一些调试的入门技巧,让你爱上console.log 先的简单介绍一下chrome的控制台,打开chr

[转]Chrome 控制台console的用法

大家都有用过各种类型的浏览器,每种浏览器都有自己的特色,本人拙见,在我用过的浏览器当中,我是最喜欢Chrome的,因为它对于调试脚本及前端设计调试都有它比其它浏览器有过之而无不及的地方.可能大家对console.log 会有一定的了解,心里难免会想调试的时候用 alert 不就行了,干嘛还要用 console.log 这么一长串的字符串来替代 alert 输出信息呢,下面我就介绍一些调试的入门技巧,让你爱上 console.log 先的简单介绍一下chrome的控制台,打开chrome浏览器,按

[Javascript] Format console.log with CSS and String Template Tags

The Chrome console allows you to format messages using CSS properties. This lesson walks you through the syntax of formatting your logs with css then refactoring into a template tag function to make formatting more reusable. const debug = (label, sty

console.log的使用

一.Console API Console.assert() 判断第一个参数是否为真,false的话抛出异常并且在console输出相应信息. Console.count() 以参数为标识记录调用的次数,调用时在console打印标识以及调用次数. Console.debug() console.log方法的别称,使用方法可以参考Console.log() Console.dir() 打印一条以三角形符号开头的语句,可以点击三角展开查看对象的属性. Console.error() 打印一条错误信

Chrome 控制台console的用法(学了之后对于调试js可是大大有用)

大家都有用过各种类型的浏览器,每种浏览器都有自己的特色,本人拙见,在我用过的浏览器当中,我是最喜欢Chrome的,因为它对于调试脚本及前端设计调试都有它比其它浏览器有过之而无不及的地方.可能大家对console.log会有一定的了解,心里难免会想调试的时候用alert不就行了,干嘛还要用console.log这么一长串的字符串来替代alert输出信息呢,下面我就介绍一些调试的入门技巧,让你爱上console.log 先的简单介绍一下chrome的控制台,打开chrome浏览器,按f12就可以轻松