如何找出警报的起因?
 我只是好奇而已 
 有什么办法在任何浏览器找出我得到的警报是从哪里提出的? 
我在Chrome上试了一下,但是警报显示时没有可用的调用堆栈。
任何想法?
您可以覆盖alert ,并为堆栈跟踪创build一个Error : 
 var old = alert; alert = function() { console.log(new Error().stack); old.apply(window, arguments); }; 
您可以修改警报来执行此操作:
 //put this at the very top of your page: window.alert = function() { throw("alert called") } 
 如何包装alert ? 
 window.original_alert = alert; alert = function (text) { // check the stack trace here do_some_debugging_or_whatever(); // call the original function original_alert(text); } 
这应该是跨浏览器。