How To Create A JavaScript Close Link

By  on  

Whenever I create a small JavaScript popup window, I offer a "close" link. Since I'm responsible for the new window, I feel it's my job to help them easily get rid of it.

The XHTML

Create an anchor with the JavaScript "close" call in the "href" attribute:

Close Window

Do not use the onClick attribute of the anchor because not everyone clicks links.

Note: I've gotten out of the habit of using JavaScript popups. They're annoying and as smooth as steel wool. I recommend using a modal box via JavaScript. Most modal box scripts allow for smooth transitions and are just as easy to close as popup windows -- plus, they don't get blocked by popup blockers. I currently use MoodalBox for my projects.

Recent Features

  • By
    I’m an Impostor

    This is the hardest thing I've ever had to write, much less admit to myself.  I've written resignation letters from jobs I've loved, I've ended relationships, I've failed at a host of tasks, and let myself down in my life.  All of those feelings were very...

  • By
    39 Shirts – Leaving Mozilla

    In 2001 I had just graduated from a small town high school and headed off to a small town college. I found myself in the quaint computer lab where the substandard computers featured two browsers: Internet Explorer and Mozilla. It was this lab where I fell...

Incredible Demos

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!