Hide errors and warnings from console

后端 未结 7 974
梦如初夏
梦如初夏 2021-01-01 23:11

In PHP and other languages there are ways to suppress error/warning messages.

Is there a way in javascript or jquery to prevent errors and warnings from being writte

7条回答
  •  有刺的猬
    2021-01-01 23:33

    After doing some research and development for this problem, I came across this solution which will hide warnings/Errors/Logs as per your choice.

    (function () {
        var origOpen = XMLHttpRequest.prototype.open;
        XMLHttpRequest.prototype.open = function () {        
            console.warn = function () { };
            window['console']['warn'] = function () { }; // For confirmation again
            this.addEventListener('load', function () {                        
                console.warn('Something bad happened.');
                window['console']['warn'] = function () { };
            });        
        };
    })();
    

    Add this code before JQuery plugin (e.g /../jquery.min.js) even as this is JavaScript code that does not require JQuery. Because some warnings are in JQuery itself.

提交回复
热议问题