views:

211

answers:

3

Hi, I was wondering if I could clear up the console with some command..

console.log(), can print... is there a command to clear up console?..

I've tried to console.log(console); and got this functions below...

assert: function assert() { [native code] }
constructor: function Console() { [native code] }
count: function count() { [native code] }
debug: function debug() { [native code] }
dir: function dir() { [native code] }
dirxml: function dirxml() { [native code] }
error: function error() { [native code] }
group: function group() { [native code] }
groupEnd: function groupEnd() { [native code] }
info: function info() { [native code] }
log: function log() { [native code] }
markTimeline: function markTimeline() { [native code] }
profile: function profile() { [native code] }
profileEnd: function profileEnd() { [native code] }
time: function time() { [native code] }
timeEnd: function timeEnd() { [native code] }
trace: function trace() { [native code] }
warn: function warn() { [native code] }
__proto__: Object

[ I guess there's no way to clear up the console... but I wanted someone to say it to me... ]

+2  A: 

If you type clear() into the console it clears it.

I don't think there is a way to programmatically do it, as it could be misused. (console is cleared by some web page, end user can't access error information)

one possible workaround:

in the console type window.clear = clear, then you'll be able to use clear in any script on your page.

cobbal
but is there a javascript for it?
Reigel
duh... the javascript function is `clear()` ... it's the same thing.
chakrit
@reigel I doubt it. updated answer
cobbal
@chakrit - lol really?
Reigel
@chakrit no, you can't call clear outside of the console (ie not in a script on the web page)
cobbal
@cobbal good point... but I don't get the 'it could be misused' part... can you share some knowledge about it?
Reigel
Hmm.... I just did it.... on my machine. Let's see...
chakrit
A possible scenario where it would be annoying: some person develops a webpage, using the clear command and it makes its way into production code. You navigate to the page and something breaks. You can't figure out why since the console has been cleared by the page.
cobbal
@chakrit - http://jsfiddle.net/bgg9e/ run this..
Reigel
@chakrit try opening the url `javascript:alert(clear)`. it will say "clear is not defined"
cobbal
well, thanks for the info cobbal ;)
Reigel
@cobbal Indeed, my mistake. What I did binded a closure with `clear` from the console, so it works. Executing it outside of console doesn't.
chakrit
+4  A: 

There's always the good ol' trick:

console.log("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

Not the most elegant solution, I know :) ... but works.

For me, I usually just print a long "-----" separator line to help make the logs easier to read.

chakrit
When you can't use a scalpel, use an axe. +1
mVChr
A: 
console._inspectorCommandLineAPI.clear()

That is working

E-D
`Uncaught TypeError: Cannot call method 'clear' of undefined`
Reigel