Window. Alert = function () {}; // overwrite the alert method // write someCodeRestore alert (1); // The alert dialog box is displayed.
I recorded this topic because someone on Weibo discussed it and I wrote the answer directly.
Method 1,Delete Alert directly.
Window. Alert = function () {}; Delete Alert; alert (1 );
This code is the simplest and most effective,Recommendation.
Method 2: retrieve the original Alert method from the prototype chain.
Alert is the window method. Therefore, find window. constructor. Prototype. Alert and call or apply.
Window. alert = function () {}; window. alert = function (s) {window. constructor. prototype. alert. call (window, S) ;}; alert (1 );
Re-define a function and overwrite it. The alert behind it is the function instead of the original alert.
Window. constructor is compatible. ie does not support window objects.
Method 3: IFRAME method.
Create a blank IFRAME, And the DOM in the IFRAME is clean. reference the alert in the IFRAME, and the warning dialog box is also displayed.
I can only say that people who come up with this method really don't understand Js.
The complexity of writing more code does not mean that the level is high.
Real code experts always write less and simpler code.