webkroll.com

Archive for the 'JavaScript' Category

Popups are not all bad

Monday, January 15th, 2007

EDIT: I have updated the script again, this time adding a timestamp to the window name in the ‘window.open’ call to avoid popups overwriting each other if multiple links are followed from a page.

Today my good friend Kay asked me if I had time to look at some nifty Javascript fellow web professional Roger Johansson had come up with to make a few modifications to suit her particular needs for a project she is currently working on.

As I am usually very curious regarding any sort of modification or enhancement of any kind of code I said I’d have a look at it.

What Roger has put together is a very well done, easy to use and accessible solution to the "popup problem" - a wild mix of inline javascript code, or onClick functions - by removing all javascript from the markup and therefore separating the presentation from the behavior layer as it should be.

The original version of Roger’s script used a ‘_blank‘ to open a new window, which is obviously sufficient but didn’t do the trick for Kay.

What Kay wanted, was a way to open popups with different dimensions via a couple of pre-defined class names (i.e. popup_small, popup_medium etc.) to get a bit more control. While we were talking about it I thought it would be even more convenient to get custom width and height values from the class names in addition to the pre-defined class names to add greater flexibility.

(more…)