Rei*_*gel 207 javascript console google-chrome
我想知道我是否可以用一些命令清理控制台..
console.log(),可以打印...是否有清理控制台的命令?
我试过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
Run Code Online (Sandbox Code Playgroud)
[我想没有办法清理控制台......但是我想让别人对我这么说......]
cob*_*bal 299
更新:截至2012年11月6日,
console.clear()是现在可以在Chrome金丝雀.
如果您clear()在控制台中键入它会清除它.
我不认为有一种方法可以以编程方式执行它,因为它可能被滥用.(控制台被某些网页清除,最终用户无法访问错误信息)
一种可能的解决方法:
在控制台类型中window.clear = clear,您将能够在页面上的任何脚本中使用clear.
cha*_*rit 130
总有很好的诀窍:
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");
Run Code Online (Sandbox Code Playgroud)
不是最优雅的解决方案,我知道:) ...但是有效.
对我来说,我通常只打印一个长的"-----"分隔线,以帮助使日志更容易阅读.
Ben*_*Ben 19
如果你使用console.clear(),那似乎适用于chrome.注意,它将输出"控制台已清除"消息.

注意,我在清除控制台后立即收到错误,因此它不会禁用控制台,只会清除它.另外,我只在chrome中试过这个,所以我不知道它是如何跨浏览器的.
编辑:我在Chrome,IE,Firefox和Opera中进行了测试.它适用于Chrome,MSIE和Opera的默认控制台,但不适用于Firefox,但它可以在Firebug中运行.
nyu*_*a7h 12
铬:
console._commandLineAPI.clear();
Run Code Online (Sandbox Code Playgroud)
苹果浏览器:
console._inspectorCommandLineAPI.clear();
Run Code Online (Sandbox Code Playgroud)
您可以创建自己的变量,该变量适用于:
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;
}
Run Code Online (Sandbox Code Playgroud)
之后,您可以简单地使用console.API.clear().
您可以使用
console.clear();
Run Code Online (Sandbox Code Playgroud)
如果你正在使用javascript编码.
否则你可以CTR+L用来清除cosole编辑器.
小智 5
console._inspectorCommandLineAPI.clear()
Run Code Online (Sandbox Code Playgroud)
那很有效
小智 5
以编程方式清除控制台的多个答案的方便汇编(来自脚本,而不是控制台本身):
if(console._commandLineAPI && console._commandLineAPI.clear){
console._commandLineAPI.clear();//clear in some safari versions
}else if(console._inspectorCommandLineAPI && console._inspectorCommandLineAPI.clear){
console._inspectorCommandLineAPI.clear();//clear in some chrome versions
}else if(console.clear){
console.clear();//clear in other chrome versions (maybe more browsers?)
}else{
console.log(Array(100).join("\n"));//print 100 newlines if nothing else works
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
197697 次 |
| 最近记录: |