[Javascript] window. alertfunction () {}; // overwrite the alert method // write some code here to restore alert (1); // The alert dialog box window appears. alertfunction () {}; // overwrite the alert method // write some code here... [javascript] window. alert = function () {}; // overwrite the alert method // write some code here to restore alert (1); // The alert dialog box window appears. alert = function () {}; // overwrite the alert method // write some code here to restore alert (1 ); // It is required that the alert dialog box be displayed to record this topic because someone has discussed it on Weibo and I wrote the answer directly. Method 1: Delete alert directly. [Javascript] window. alert = function () {}; delete alert; alert (1); window. alert = function () {}; delete alert; alert (1); this code is the simplest and best performing, and is recommended. 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. [Javascript] window. alert = function () {}; window. alert = function (s) {window. constructor. prototype. alert. call (window, s) ;}; alert (1); window. alert = function () {}; window. alert = function (s) {window. constructor. prototype. alert. call (window, s) ;}; alert (1); Re-defines a function and overwrites it. The following alert function is not 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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.