Check whether the pop-up window blocking function is activated

Source: Internet
Author: User

Whether or not you think the pop-up window is a modern form of plague, just like the locusts and branny's CD, the truth is that they have been evil for a while. Many network-based applications use pop-up windows to do some useless things, from displaying the Help page to displaying various product pictures. Unfortunately, if the agent is installed in the browser of the client to prevent the pop-up window from being activated, it is useless for sellers to use the pop-up window.

A feasible solution is to fill in the message "This website uses a pop-up window, please make sure you do not use the pop-up window blocking function" everywhere on your website. However, it seems unrealistic to allow users not to use the pop-up window function when Browsing Your webpage. What you need to do is to check whether the user has used the function to block the pop-up window, so that your website can adapt to browsing needs.
Use a pop-up window to block the pop-up window
The method I chose to complete this function is to open a pop-up window. Of course, this means that you must be very careful when programming, because if I do not, errors may occur on the client. To maintain this mentality, I installed Google Toolbar and used an onload event handler to encode the page, this loading event processor can detect software that prevents pop-up windows. The result is shown in Listing A and Listing B.
The method shown in Listing A is that the loading event processor (called setEvents) is hit and it tries to open A popupchild.html page displayed in Listing B. In this way, it seems that this method is sufficient to determine whether the function to block the pop-up window is running, but this is not always the case. This depends on the installation of the interception function. What we need is to display "Hello, world!" In the subwindow !" Or something else. This page uses the setTimeout method to call the checkChild method in a delayed manner. This gives the pop-up window the time needed to change a hidden input object in the parent window and close it. Once this is done, the checkChild method will check to hide the input object and check whether the content of the subwindow has changed. If its content has been modified, the pop-up window function will take effect, which means that the customer has not used the Interception Function.
During the test, there are two most difficult parts: accessing the hidden input object in the parent window and estimating the time when the pop-up window is opened. The first problem is easily solved by using window. opener of the Document Object Model. The second part is more difficult. After all, when I use these examples, both the browser and server are on the same machine. So even if these examples run normally here, they may not work for others. You must find a better solution.
A better way
One interesting thing about javascript is that it is not affected by the browser, and it is relatively consistent. If a problem occurs in one browser, it is strange that it is unlikely that it will happen in other browsers. For example, if you use an object to write warning code, "[object]" is displayed in Microsoft Internet Explorer and "[object Window]" is displayed in Mozilla. Another interesting thing is that the above problem only occurs after the object is created. You can refer to the Listing C example. We need to pay attention to the above problems, because we only check whether the pop-up window blocking function is enabled, it is just an empty page.
I wrote this code because some developers and technical support staff spent three hours recently to solve this problem in the conference room. Remote customers insist that they do not use the pop-up window Interception Function. When everyone is exhausted, someone proposes to check the software installed by the customer. At the very end of the list, there is a program to add cute smiling faces to the customer's email. Through a simple check, we can find that this program not only supports adding smiling faces to emails, but also intercepts pop-up windows. The user installed this item but was unaware of it. This is what I want to avoid when writing 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.