是否有“所有警报关闭”脚本将禁用所有警报?

时间:2013-09-28 14:40:10

标签: javascript prototype alert

假设我在故障排除过程中使用了大量警报,而不是重新开始并将其全部删除,我宁愿全部关闭它们?可以吗?也许通过重写`alert.prototype?

1 个答案:

答案 0 :(得分:1)

我想你需要这样的东西:

var oldAlert = window.alert;

window.alert = function(){
   if (enableAlertFunction){
      oldAlert.apply(window,arguments);
   }
}

enableAlertFunction用于打开/关闭所有alert。请务必先在页面上的所有代码之前运行此代码。