jQuery is it Possible to bind() to the alert() event so I can bypass the default message box
I want bind to an event but I am not sure if its possible开发者_开发百科. I have several coders on a project of which some use the standard alert() function. I want to catch that event when its fired off and display a jquery ui module. Is this even possible? I know I can go through and replace the alerts with a dialog() but i'd rather not sore through thousands of lines of code cross several files to do it if I don't have to.
The alert
function does not fire an event, but you can override it:
//Save the old alert function if necessary
var savedAlert = window.alert;
window.alert = function(str){
//Show dialog
}
This would have to run before any calls to alert()
.
You could directly overwrite the window.alert
method with one of your own functions that creates a jQuery UI Dialog instead. This would destroy the alert box for every other scenario, but you could cache it first in case you still wanted to use it.
var _alert = window.alert;
window.alert = function (message) {
// create/show dialog
};
精彩评论