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
    How to Create a RetroPie on Raspberry Pi – Graphical Guide

    Today we get to play amazing games on our super powered game consoles, PCs, VR headsets, and even mobile devices.  While I enjoy playing new games these days, I do long for the retro gaming systems I had when I was a kid: the original Nintendo...

  • By
    Create a CSS Flipping Animation

    CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...

Incredible Demos

  • By
    Duplicate DeSandro’s CSS Effect

    I recently stumbled upon David DeSandro's website when I saw a tweet stating that someone had stolen/hotlinked his website design and code, and he decided to do the only logical thing to retaliate:  use some simple JavaScript goodness to inject unicorns into their page.

  • By
    Rotate Elements with CSS Transformations

    I've gone on a million rants about the lack of progress with CSS and how I'm happy that both JavaScript and browser-specific CSS have tried to push web design forward. One of those browser-specific CSS properties we love is CSS transformations. CSS transformations...

Discussion

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