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');

5
  • 1
    You probably can't, what do you need it for? You can use console.warn and console.error to differentiate your outputs Commented Nov 12, 2017 at 14:32
  • You can look at this question, I think it will help you stackoverflow.com/questions/9781218/… Commented Nov 12, 2017 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. Commented Nov 12, 2017 at 14:36
  • 1
    wow, the unknowledge is for close questions, It would be a crime to have questions! Commented Nov 12, 2017 at 14:38
  • stackoverflow snippets does support some placeholders like %i, %s, %o, but they don't support colors, so no %c. Commented Nov 12, 2017 at 14:45

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.