Is your pop-up blocked? - Web Development - Techguide

Is your pop-up blocked?

 

Summary

Love or loathe it, a pop-up window is sometimes your best delivery mechanism. But if you are using pop-ups, you'll need a way to detect pop-up blockers. Here's how.

Events

Echelon 2012
June 11 and 12, 2012

University Cultural Centre, National University of Singapore

Startup Asia Jakarta 2012
June 7 and 8, 2012

12th Floor, Annex Building, Wisma Nusantara Complex, Jl. M.H. Thamrin No. 59 Jakarta 10350, Indonesia

MMA Forum Singapore
April 23-25, 2012

Grand Hyatt Singapore

Whether or not you think that pop-ups are a modern form of pestilence, like locusts and Britney Spears CDs, there are times when they are a necessary evil. Many Web-based applications use pop-ups for a number of mundane tasks ranging from displaying help pages to displaying different images of available products. Unfortunately, if the client's browser has a pop-up blocker installed and enabled then you're pretty much out of luck when it comes to using pop-ups.

One possible solution is to have messages throughout your site saying something like, "This site utilizes pop-up windows. Please ensure that your pop-up blocker is disabled for this site." But that's not very user-friendly to make someone deactivate the blocker just to use your site. What's needed instead is a way to tell if a user has a pop-up block so that your site can then tailor the browsing experience.

Use a pop-up to kill a pop-up

The method that I've chosen to accomplish this task is by trying to open a pop-up window. Of course, this means that I have to be rather defensive in my programming because if I'm not, the possibility exists for the client seeing an error. With this in mind, I installed the Google Toolbar and began to code a page with an onload event handler that checks for pop-up blocking software. The results of this endeavor are shown in Listing A and Listing B.

The way that the page shown in Listing A works is that the onload event handler, setEvents, is fired and it attempts to open the page popupChild.html shown in Listing B. While it may seem that an error trap is enough to determine if the pop-up worked, that isn't always the case. Depending on the pop-up blocker installed there may or may not be an error. What's needed is essentially for the child window to stand up and say, "Hello, world!" or something along those lines. The page then uses the setTimeout method to delay the invocation of the function checkChild; this gives the pop-up the time needed to alter a hidden input object on the parent window and close itself. Once this has been accomplished, the function checkChild checks the value of the hidden input object to determine if the child window modified its contents. If the contents have changed, then the pop-up worked, which means no pop-up blocking software.

The two hardest parts of this entire testing process are accessing the hidden input object on the parent window and estimating how long it should take for the pop-up to open. The first problem is easily solved through the use of the Document Object Model's window.opener property. The second part is a lot harder; after all, as I play around with these examples the browser and the server are on the same machine. So while these examples worked for me, they might not work for everyone everywhere. There has to be a better way.

A better way

One of the interesting things about JavaScript is that, regardless of the browser, it is relatively consistent. If something works on one browser, the odds are that only a little tweak will be necessary to get it to work on another. For example, coding an alert with an object results in "[object]" in Microsoft Internet Explorer and "[object Window]" in Mozilla. Another interesting thing is that the aforementioned only happens when the object is actually created. The result of this line of reasoning is shown in Listing C. Note that because we're only checking to determine if a pop-up can be opened, it's merely an empty page.

One of the reasons that I developed this code is because, recently, several developers and technical support people spent three hours in a conference room dealing with this issue on our order entry system. A remote client insisted that they didn't have a pop-up blocker; only after having exhausted all possible problems on our end did someone suggest reviewing the client's installed programs. Near the bottom of that list was a program that added cute little smiles to the client's e-mails. After a little research it was determined that not only did it add smiles to e-mail, but among other things, it also blocked pop-ups. The user had installed a pop-up blocker and didn't even realize it, which is the problem that I'm trying to avoid in the future with this code.

Talkback

Add your opinion

In order to post a comment, you need to be registered. (Sign In or register below)

Post your comment

ZDNet Asia Live

Fanboys on AV for Mac: "ludicrous" "a waste of time" "The Mac will protect me" "the most secure ever" "impenetrable" http://t.co/a1o2Sz7E

RT @ameliatmy: the hottest angel investment & venture capital event in #MALAYSIA! will u be there? http://t.co/ChSjkmzu #ABAF

Singapore Game Box in the ZDnet news!
http://t.co/UuTs0SqX http://t.co/YdPKmm39

#radio Radio Bolivia by EnjoyIT 1.0 http://t.co/fdlBPOeI

RT @zdnetasia: SingTel acquires HungryGoWhere for US$9.4 million. http://t.co/Qho1REVZ

Gartner: Mobile CRM gives better ROI than social - http://t.co/s5OfTAXK #CRM

RT @zdnetasia: S'pore sets up portal to grow games sector. http://t.co/In8gtj7L

#Malaysia: 20% yoy rise in overall #wages for both direct and non-direct labor. http://t.co/5T2e0LUU

RT @mikebuetow: #Malaysia: 20% yoy rise in overall #wages for both direct and non-direct labor. http://t.co/5T2e0LUU

@88tc88 RT @KevinZDNetAsia: User experience more important to app monetization than actual content http://t.co/ogbD5wyI… #li #dm12

Dubbed the first social #Olympics, this year's summer games have some of the strictest social rules for all involved http://t.co/4HlcqhW3

Value of big data analytics largely untapped - Zd Net http://t.co/ZuhPrCN4: Pushing cloud limits for d... http://t.co/VyOU0vHz #TheBIBlog

Value of big data analytics largely untapped http://t.co/026PCpSc @zdnetasia

RT @data_nerd: Value of big data analytics largely untapped http://t.co/026PCpSc @zdnetasia

Active WebTraffic - Downloads - ZDNet Asia: Active WebTraffic is a web promotion tool that includes ... http://t.co/fMJepPh8 #webtraffic

So much as we know , MTK6575 extremely integrated frequency1GHz ARM Cortex-A9 processor, the superiority of 3G / HSPA Modem, and help the...

14 hours ago by y15822137359 on 5 SaaS adoption speed bumps to avoid

I reckon your view: "CRM is strategy, not software", if a company replicating the approach uses in ERP implementation into CRM, what they...

1 day ago by wykoong on Gartner: Mobile CRM gives better ROI than social

This video will teach you about the Excel fill handle but also provide you with a workook to download... http://www.youtube.com/watch?v=...

2 days ago by TradeBrother on A quick fill handle trick for Microsoft Excel

waiting...

4 days ago by eapete on What should count in a company's market value?

Boy, you've opened a can of worms now.

Wait for the rants & raves.

4 days ago by eapete on What should count in a company's market value?

I was puzzling before this whether to replicate the success formula we executed for a financial institute, and come out with a standard s...

4 days ago by wykoong on Drop the egos, copy ideas, then innovate