FF1+ IE5+

Auto-centering Popup Window

Author: Eric King

Description: Use this practical DHTML script to not only open up links in a secondary popup window, but one that's centered in the middle of the user's screen. Browsers other than NS 4+ or IE 4+ will still open the window, only that it won't be centered. Excellent!

Demo: Click on any one of the below links:

CNN.com | Website Abstraction | News.com | Freewarejava.com

Directions: Developer's View

Step 1: Insert the below inside the <head> section of your page:

Select All

Step 2: Now, for each involved link, add the part in red to its <a> tag, as follows:

<a href="http://wsabstract.com" onclick="NewWindow(this.href,'name','400','400','yes');return false">Website Abstraction</a>

where the two numbers (400) denote the dimensions of the window, and the "yes", whether this window will be scrollable or not (value of "no" disables scrolling).

You're done!

Technical Note

It is possible to configure the popup window beyond simply its dimensions and resizability, so as to contain default window features such as the Tool or Directory bar. To do so, concat one or more of the below to the end of variable "settings", inside code of Step 1:


For example, to give the window a location bar, variable "settings" should look like this:

settings =
left='+LeftPosition+',scrollbars='+scroll+',resizable, location'

Piece of cake, right?

Wordpress Users: Step by Step instructions to add ANY Dynamic Drive script to an entire Wordpress theme or individual Post