Dan Johnson
Dan Johnson

Reputation: 1482

Style console.log output and run functions

After having a little snoop around the source code for http://pinterest.com, I noticed how they use the console to communicate with users (Appears to only work in Chrome).

enter image description here

Also, if I enter joinUs() on the console log, a function is run which directs me to a new page.

I attempted to run a function within the console log on my own website by declaring a function:

function testFunc(){
    console.log('Hello world!');
}

But if I try entering testFunc() on the console log, I get the following error:

ReferenceError: testFunc is not defined

Does anybody have any information on how to style the output of the console log, and how to run a function from within the console?

Upvotes: 0

Views: 237

Answers (1)

Tim
Tim

Reputation: 2440

For styling, you could check https://github.com/adamschwartz/log
If you read through the code I'm sure you can figure out how it works.

As for having testFunc available, try explicitly assigning it to window, so do window.testFunc = function () { console.log('Hello world!') };. That should work.

Upvotes: 1

Related Questions