If you thought opening a link in a new window was bad…

We hear it all of the time, “Don’t open links in a new window.” However, sometimes it makes sense, whether it’s because a client insists on it, or because way the site is meant to be used, (and is used by its users), works better if some, links are opened in new windows. The fact of the matter is that sometimes you’ve just got to open a new window.

But, what happens when someone else decides to close that window? Confused users, that’s what.

I recently came across a site that does just that. It checks to see if there’s an opener object, (we’re talking javascript now), and if there is one, it redirects the opener to its address and closes itself.

Here’s the code:

function checkForPopup()
                {
                    if (typeof(window.opener) != 'undefined')
                    {
                        var queryString = window.location.search.substring(1);
                        if (queryString.indexOf('cliententry=true') == -1)
                        {
                            try
                            {
                                if(!window.opener.closed)
                                {
                                    window.opener.top.location = window.location;
                                    window.close();
                                }
                             }
                             catch(e)
                             {
                                //We Ignore this error becuase the user
                                //may have closed the opener
                             }
                        }
                    }
                }

Seriously! I was disgusted. There is no better way to mess with a user than that!