Disable alert(); [duplicate]

Code that is generated on my page that I cannot control contains an alert. Is there a jQuery or other way to disable alert() from working?

The javascript that is being generated that I want to disable/modify is:

function fndropdownurl(val)
1317 { var target_url
1318 target_url = document.getElementById(val).value;
1319 if (target_url == 0)
1320 {
1321 alert("Please Select from DropDown")
1322 }
1323 else
1324 {
1325 window.open(target_url);
1326 return;
1327 }
1328 } 

I want to disable the alert on line 1321




Simply overwrite alert with your own, empty, function.

window.alert = function() {};

// or simply
alert = function() {};

This works in Chrome and other browsers with the console.log function.

window.alert = function ( text ) { console.log( 'tried to alert: ' + text ); return true; };
alert( new Date() );
// tried to alert: Wed Dec 08 2010 14:58:28 GMT+0100 (W. Europe Standard Time)

You can try and make a new function function alert() { } , this is not going to do anything since is empty and will overwrite the existing one.


Try this:

alert = function(){};

The second line assigns a new blank function to alert, while not breaking the fact that it is a function. See: http://jsfiddle.net/9MHzL/


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.