This is wierd behavior in IE 6 (works in FireFox)
This overrides alert function correctly 'function alert (s,t,icon)' but this
'window.alert=function(s,t,icon)' does not, the strangest part is that
' window.prompt=function(string,defaultValue,fun,funArguments,scope)' does behave correctly and overrides the prompt function.
The thing that I don't see is why alert function cant be overwritten this same way even that it resides in window scope.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Overwrite alert() function</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!-- begin hiding
window.alert = function() {
document.getElementsByTagName('body')[0].appendChild(document.createTextNode('AAAH! '));
};
window.onload = function() {
alert();
};
// end hiding -->
</script>
</head>
<body>
</body>
</html>
One small suggestion -- and I don't know how much it will affect things -- but any time you do foo = function() {}, you should to end it with a semi colon, as you are actually assigning a value to something. similar to var foo = "bar";.
So it should look like:
Code:
window.alert = function() {
// your code here
}; // <<--- semi colon
Since JavaScript recognizes newline characters as the end of a programming line, it shouldn't make a difference. Something else must be going on. What part of the HTML document is this JavaScript being included in? Was there a JavaScript error that perhaps was fixed when you changed the function definition to "function alert()"?
function alert (s,t,icon){
}
window.alert=function(s,t,icon){
};
This two function declarations should be this same, all I did was change how the function was declared to get it working in IE, so I really don't think that there were any bugs introduced of fixed.
Bookmarks