Is it possible to render HTML into Javascript console?

走远了吗. 提交于 2019-12-01 00:33:28
j08691

In a way it's possible using the CSS format specifier.

Example:

console.log("%cThis will be formatted with large, blue text", "color: blue; font-size: x-large");

The CSS format specifier allows you to customize the display in the console. Start the string with the specifier and give the style you wish to apply as the second parameter.

This feature is supported by all main browser developer tools. See the reference for the Chrome DevTools, the one for the Firefox DevTools or the one for Firebug.

So while you can't use HTML per se, you can style whatever text you want using CSS to mimic many HTML elements:

console.log("%cHello!", "font-size: 3em");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!