Correctly Suppressing Warnings in DataTables?

前端 未结 6 2221
小蘑菇
小蘑菇 2020-12-24 12:13

I\'m trying to correctly suppress warnings (alerts) in DataTables. The standard behavior of DataTables is to throw a javascript alert when an error occurs; however, this is

6条回答
  •  攒了一身酷
    2020-12-24 12:39

    I modified the native alert using this closure function to redirect DataTables warnings to the console.

    window.alert = (function() {
        var nativeAlert = window.alert;
        return function(message) {
            window.alert = nativeAlert;
            message.indexOf("DataTables warning") === 0 ?
                console.warn(message) :
                nativeAlert(message);
        }
    })();
    

    It restores the window.alert to its native function on first trigger. If you don't want it to restore to the original alert, just comment out the window.alert = nativeAlert; line.

提交回复
热议问题