Has anyone got any experience with overriding the alert()
function in JavaScript?
Ladislav.
For IE8 you can redefine alert() like this way
/**
* Definition of global attached to window properties
*/
(function() {
nalert = window.alert;
Type = {
native: 'native',
custom: 'custom'
};
})();
/**
* Factory method for calling alert().
* It will be call a native alert() or a custom redefined alert() by a Type param.
* This defeinition need for IE
*/
(function(proxy) {
proxy.alert = function () {
var message = (!arguments[0]) ? 'null': arguments[0];
var type = (!arguments[1]) ? '': arguments[1];
if(type && type == 'native') {
nalert(message);
}
else {
document.write('I am redefiend alert()
Alert say: '+message+'
');
}
};
})(this);
and call as
alert('Hello, hacker!');
nalert('I am native alert');
alert('Hello, user!', Type.custom);