More Accessible Popup Windows (If Coerced)
There’s something extremely annoying about pop-up windows and yet clients often seem to demand them as though they were the answer to that internal fear users will follow a link and never return. My advice from the beginning is if you have such a link remove it immediately - problem solved. There’s a lot to be said for never linking to sites far more interesting than your own.
In real life this fear just isn’t founded and the last thing you should be doing is trying to hold your users captive. If they want to leave then let them, for Christ’s Sake! It’s repeat visitors and conversions that make a successful site not keeping your window open in some sub-level dungeon on the task bar. You’ve probably figured already that pop-ups confront users with a back button that isn’t going to work. And sometimes the window is chromeless. It’s obtrusive, offends a large number of your users, and will confuse the hell out of sighted users let alone someone using assistive technology. And they should never EVER occur without a warning! OK the rant is over for now so we’ll carry on (we understand that pop-up windows are bad for usability and shitty and considered industry worst practice). About the only thing you should be popping up in a new window is a PDF (Portable Document Format) file in its native application.
But sometimes you’re forced with your back against the wall to suck air and implement the suckers! You’re handed deprecated target="_blank" attributes on external links that smack the users in the forehead [Steven takes forefinger and pokes each reader three or four times firmly on the forehead saying "How do you like that?!"]. Delete all those target="_blank" attributes for a start, its a behaviour not content and you’ll oneday have to go clean the suckers out of there eventually so now is the best time to do it. They’re even the most primitive way of achieving popup windows, so get the fuckers out of there now! Begone shite. Don’t you loathe the way target="_blank" instantly throws up a full sized new window - Whoa, where the friggen hell am I again? WTF (again)? How about letting me, the user, make the decision about whether or not to open a new window [ranting again!].
OK the torture is getting prolonged here. If coerced into doing this, you need to look at pop-ups as a behaviour layer issue. If it’s this or target="_blank". Yes it’s sucky, but at least you can implement them in a sensible way if you’re ever coerced by the prospect of unemployment. So you’re looking for an Unobtrusive JavaScript solution, not a content solution to achieving your result. The benefit of this is you can at least provide for graceful degradation (if they don’t have JavaScript they get a normally functioning link to a new page), window size (definately not full screen) and browser features available to the user (preferably all of the features enabled).
I’m not sure where exactly this snippet came into my arsenal (mainly because I have hardly ever had a call to use it). But maybe it will come in handy for your coerced situation. There’s no crime in trying to make an intolerable thing out of an abject bad situation. Name this script popups.js (I should metion this code wasn’t written by me) and call it from an external file in the head section of your document. Then when you want your external link to open in a new window just include rel="external" as an attribute of the link. In that way, only links you specifically want to open in new windows will do so.
function prepareLinks() { if(!document.getElementsByTagName) return false; var links = document.getElementsByTagName("a"); for(var i=0; i<links.length; i++ { if((links[i].getAttribute("rel") == "external") || (links[i].getAttribute("rel") == "pdf")) { links[i].onclick = function() { popUp(this.getAttribute("href")); return false; } } } }function popUp(winURL) { window.open(winURL, "external", "width=420, status=1,scrollbars=1,toolbar=1, location=1,menubar=1, directories=1,resizable=1"); }
Roger Johansson has another script using class instead of rel to trigger the opening of new windows. My preference goes to the rel attribute, but you’re free to choose. Either way these scripts fall back nicely for non-JavaScript enabled users. So, overlooking the suckiness of having to implement a feature that continuously turns up as one of the 10 biggest web design mistakes, and was identified as long ago as 1999 by Jakob Nielsen as having usability issues - there you go. You can run along and shoot your foot off with it.
If I recall where I picked this script up I’ll put a link here, it’s a rather short list of suspects. Best of luck. And doesn’t it strike you as odd that since popups have been criticised now for at least 9 years at a high professional level we’re still having to do this shite? I’m friggen bowled over. Another WTF moment brought to you by the letter K and the numbers 3, 4 and 25. Exit and run…







