If you often use shortcut keys to navigate the web or any other program for that matter, you probably expect the ESC key to close popups and message boxes (alerts). When using popup windows on the web, this is however not the case. If you use popups to show full sized images of thumbnails, it would be natural to press the ESC key in the expectation of the popup to close.

To achieve this functionality, we have to place a little JavaScript in the popup window. Add the following to the head section of the html page: