kottke.org home archives + xml about kottke.org contact me
kottke.org - home of fine hypertext products

A short guide to doing

A short guide to doing JavaScript pop-up windows properly: specify your pop-up function in the href attribute instead of the onclick attribute. If you must use the onclick attribute, specify "javascript://" in the href attribute, not "#" because that will take you to the top of the page, a behavior which is not intended or appreciated by the Web user.

Preferred**: <a href="foo.html" onclick="window.open(this.href);return false;">
Good: <a href="javascript:PopUp()">link</a>
Good: <a href="javascript://" onclick="PopUp()">link</a>
Bad bad: <a href="#" onclick="PopUp()">link</a>

** Milo writes in with an even better method of doing pop-ups: <a href="foo.html" onclick="window.open(this.href);return false;">. Benefits include non-JS browser compatibility and shift/right click compatibility.

More about this page

This entry was published on December 27, 2001 at 09:12 am.

kottke.org is a weblog about the liberal arts 2.0 edited by Jason Kottke since March 1998. You can read about me and kottke.org here. If you've got questions, concerns, or an interesting link for me, send them along. Here's the kottke.org RSS feed kottke.org RSS feed.

Advertisement

dot dot dot

Advertise on kottke.org via The Deck.

Looking for work? Tags, tags, tags!

Many posts on kottke.org have been "tagged" with keywords, which activity results in collections of related posts like sports, infoviz, or bestof.

Recently popular tags (last 3 weeks)

swimming   photography   olympics   trackandfield   video   sports   movies   lists   language   science   green   food   books   tv   design

All-time popular tags

movies   photography   books   nyc   science   food   lists   design   business   sports   video   weblogs   music   bestof   art

Some of my favorite tags

photography   economics   lists   bestof   infoviz   food   nyc   firstworldproblems   cities   restaurants   video   timelapse   interviews   language   maps   fashion   nsfw   remix  

Random tags

sunshine   prison   cities   barcade   marypoppins   lifeafterpeople   realestate   cars   fundraising   hosseinderakhshan   fridakahlo   sony   pentagram   movies   im

kottke.org

You're visiting kottke.org. All content by Jason Kottke (contact me) unless otherwise noted, with some restrictions on its use. Good luck will come to those who dig around in the archives. If you've reached this point by accident, I suggest panic.