简体   繁体   English

在浏览器控制台javascript中阻止警告消息

[英]Prevent warn message in browser console javascript

I'm developing using ionic framework, and often I see this warn: 我正在使用离子框架进行开发,并且经常看到以下警告:

在此处输入图片说明

Text version: 文字版本:

A DOM event generated from JavaScript has triggered a default action inside the browser. 由JavaScript生成的DOM事件已触发浏览器内部的默认操作。 This behavior is non-standard and will be removed in M53, around September 2016. See https://www.chromestatus.com/features/5718803933560832 for more details. 此行为是非标准的,将于2016年9月左右在M53中删除。有关更多详细信息,请参见https://www.chromestatus.com/features/57188​​03933560832

I tried this code to avoid the above warn: 我尝试使用此代码来避免上述警告:

fnWarn = console.warn;
console.warn = function() {
    if (/A DOM event generated from JavaScript/i.test(arguments[0])) {
        return false;
    }
    fnWarn.apply(console, arguments);
}

But the warn still shows up. 但是警告仍然出现。

Is there any way to hide it? 有什么办法藏起来吗?

David R linked to this in his comment which redefines console , so really kudos should go to him. 大卫·R连接到这个在他的评论这重新定义console ,所以真正的荣誉应该归他。 This should help but isn't advisable to do: 这应该有所帮助,但不建议这样做:

var console = {};
console.log = function(){};
console.warn = function(){};
console.info = function(){};
console.error = function(){};

If using this method you should also include: 如果使用此方法,则还应包括:

window.console = console;

to cover browsers that don't support console 涵盖不支持console浏览器

It should be noted that when using bundler or similar to package your app they have the option to remove logs, warnings etc if my memory serves. 应该注意的是,当使用捆绑软件或类似工具打包您的应用程序时,如果我的内存可用,它们可以选择删除日志,警告等。 If you're not packaging stuff up yourself then you could use the min version of Ionic it should exclude logs, warnings, info etc. 如果您自己没有打包东西,则可以使用Ionic的最小版本,它应排除日志,警告,信息等。

Also it doesn't appear to have that message in the latest version of ionic 而且在最新版本的ionic中似乎没有该消息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM