清除 Google Chrome 中的 javascript 控制台

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3011600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:54:50  来源:igfitidea点击:

clear javascript console in Google Chrome

javascriptconsolegoogle-chrome

提问by Reigel

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?..

console.log(), 可以打印... 有没有清理控制台的命令?...

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

我已经尝试console.log(console);并在下面获得了这个功能......

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... ]

[我想没有办法清理控制台......但我想有人对我说......]

回答by cobbal

Update: As of November 6, 2012, console.clear()is now availablein Chrome Canary.

更新:截至2012年11月6日,console.clear()现在可以在Chrome金丝雀。



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

如果您clear()在控制台中键入它会清除它。

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.

在控制台类型中window.clear = clear,那么您就可以在页面上的任何脚本中使用 clear 。

回答by chakrit

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

or a shorter variation of the above:

或更短的上述变化:

console.log('\n'.repeat('25'));

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.

对我来说,我通常只是打印一个长的“-----”分隔线来帮助使日志更易于阅读。

回答by RealWorldCoder

This seems to work just fine:

这似乎工作得很好:

console.clear();

回答by Ben

If you use console.clear(), that seems to work in chrome. Note, it will output a "Console was cleared" message.

如果您使用console.clear(),这似乎适用于 chrome。请注意,它将输出“控制台已清除”消息。

I tested this by racking up a ton of Javascript errors.

我通过收集大量 Javascript 错误对此进行了测试。

Note, I got an error right after clearing the console, so it doesn't disable the console, only clears it. Also, I have only tried this in chrome, so I dont know how cross-browser it is.

请注意,我在清除控制台后立即出错,因此它不会禁用控制台,只会清除它。另外,我只在 chrome 中尝试过这个,所以我不知道它是如何跨浏览器的。

EDIT:I tested this in Chrome, IE, Firefox, and Opera. It works in Chrome, MSIE and Opera's default consoles, but not in Firefox's, however, it does work in Firebug.

编辑:我在 Chrome、IE、Firefox 和 Opera 中对此进行了测试。它适用于 Chrome、MSIE 和 Opera 的默认控制台,但不适用于 Firefox,但它确实适用于 Firebug。

回答by Dean Meehan

Chrome Console Clear button

Chrome 控制台清除按钮

If you want to just clear the console when debugging, you can simply click the "ban-circle" ?button to clear console.log.

如果只想在调试的时候清空控制台,可以直接点击“ban-circle” ?按钮清空console.log。

Alternatively just press "Ctrl+L"to clear the console using your keyboard.

或者,只需按“Ctrl+L”即可使用键盘清除控制台。

回答by nyuszika7h

Chrome:

铬合金:

console._commandLineAPI.clear();

Safari:

苹果浏览器:

console._inspectorCommandLineAPI.clear();

You can create your own variable, which works in both:

您可以创建自己的变量,它适用于以下两种情况:

if (typeof console._commandLineAPI !== 'undefined') {
    console.API = console._commandLineAPI;
} else if (typeof console._inspectorCommandLineAPI !== 'undefined') {
    console.API = console._inspectorCommandLineAPI;
} else if (typeof console.clear !== 'undefined') {
    console.API = console;
}

After that, you can simply use console.API.clear().

之后,您可以简单地使用console.API.clear().

回答by Avinash Raut

you can use

您可以使用

console.clear();

if you are working with javascript coding.

如果您正在使用 javascript 编码。

else you can use CTR+Lto clear cosole editor.

否则你可以CTR+L用来清除cosole编辑器。

回答by AbhiNickz

PressCTRL+LShortcut to clear log, even if you have ticked Preserve logoption.
Hope this helps.

PressCTRL+L清除的快捷方式log,即使您勾选了Preserve log选项。
希望这可以帮助。

回答by AbhiNickz

On the Mac you can also use ?+Kjust like in Terminal.

在 Mac 上,您也可以?+K像在终端中一样使用。

回答by E-D

console._inspectorCommandLineAPI.clear()

That is working

那是工作