How to overwrite inline javascript native method

Let's say we have a warning window method. I would like to improve it with nice alertbox.

I also want to keep the existing notification method so that we can go back after the completion of our application.

Something like this, but its throwing error in firefox console.

window.prototype.alert = function(){ } 
+4
source share
2 answers

You can:

 var base = window.alert; window.alert = function(message) { document.getElementById("myalertwidget").innerHTML = message; return base.apply(this, arguments); }; 
+3
source

There is no window.prototype object. window is a global javascript context object and is not created from a prototype.

However, what you want to do is possible with the following code:

 window.old_alert = window.alert; window.alert = function(txt) { // do what you need this.old_alert(txt); } 
+5
source

Source: https://habr.com/ru/post/1391621/


All Articles