0

I saw this code in other question , and i know that it works in chrome console, but this not work in javascript console, like jsbin or stackoverflow snippet.

How can i make it work in all console, with compatibility?

console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
ESCM
  • 269
  • 2
  • 13
  • 1
    You probably can't, what do you need it for? You can use `console.warn` and `console.error` to differentiate your outputs – SourceOverflow Nov 12 '17 at 14:32
  • You can look at this question, I think it will help you https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color – C'estLaVie Nov 12 '17 at 14:33
  • 2
    I'm voting to close this question as off-topic because features provided by console in JSBin or Stackoverflow snippets are a subset of those available in the browser. – Nisarg Shah Nov 12 '17 at 14:36
  • 1
    wow, the unknowledge is for close questions, It would be a crime to have questions! – ESCM Nov 12 '17 at 14:38
  • stackoverflow snippets does support *some* placeholders like %i, %s, %o, but they don't support colors, so no %c. – dfsq Nov 12 '17 at 14:45

2 Answers2

2

You simply can't. They need to implement it first.

Mads03DK
  • 46
  • 3
0

Here is a very simple implementation without "%" syntax (I just want to show you that you don't really need this feature) :

var styles = "background:#222;color:#bada55";
log("you could do", style(styles, "this"));
log("you could do", style(styles, "this"));
log("you could do", style(styles, "this"));
<pre id="pre"></pre>
<style>div{border-bottom:1px solid #ddd;padding:.5em}</style>
<script>!function(pre){this.log=function(){var a=document.createElement("div");a.innerHTML=Array.prototype.join.call(arguments," ");pre.appendChild(a)};this.style=function(a,b){return'<span style="'+a+'">'+b+"</span>"};}(document.getElementById("pre"));</script>