Window. Alert = function () {};____; alert (1 );

Source: Internet
Author: User
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.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.