为了账号安全,请及时绑定邮箱和手机立即绑定

在Google Chrome中清除JavaScript控制台

在Google Chrome中清除JavaScript控制台

心有法竹 2019-12-13 10:08:05
我想知道是否可以使用某些命令清除控制台。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[我想没有办法清理控制台...但是我希望有人对我说...]
查看完整描述

3 回答

?
米琪卡哇伊

TA贡献1998条经验 获得超6个赞

console.clear()是现在可以在Chrome金丝雀。


如果您输入clear()控制台,它将清除它。


我认为没有办法以编程方式进行此操作,因为它可能会被滥用。(控制台已通过某些网页清除,最终用户无法访问错误信息)


一种可能的解决方法:


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


查看完整回答
反对 回复 2019-12-13
?
达令说

TA贡献1821条经验 获得超6个赞

总是有个好办法:


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

我知道这不是最优雅的解决方案:) ...但是可以。


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


查看完整回答
反对 回复 2019-12-13
?
素胚勾勒不出你

TA贡献1827条经验 获得超9个赞

铬:


console._commandLineAPI.clear();

苹果浏览器:


console._inspectorCommandLineAPI.clear();

您可以创建自己的变量,该变量在两种情况下均可使用:


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;

}

之后,您只需使用即可console.API.clear()。


查看完整回答
反对 回复 2019-12-13
  • 3 回答
  • 0 关注
  • 723 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号