Click here to Skip to main content
Licence CPOL
First Posted 11 May 2002
Views 80,046
Bookmarked 21 times

Centered Popup Windows

By | 11 May 2002 | Article
A couple of functions to wrap the process of working with popups.

Introduction

Recently, I have been doing a great deal of web development. Because of which, I decided to create an API set for the more commonly used functions I routinely needed to implement in JavaScript. This article contains two functions from my API set that may be of interest to web developers at large.

These functions wrap the process of creating and destroying popup windows. The benefit from using this is that it automatically centers your popup gracefully. By gracefully, I mean that it will center when possible and leave the window be if not possible without producing an error message to the user. Typically, most have their popups only centered on the 4.0+ (JavaScript 1.2+) browsers, but this goes one step further and centers the popup on Netscape 3.0 as well by accessing the AWT from JavaScript.

The two functions involved here are CreateWnd() and DestroyWnd(). As you might imagine, CreateWnd() will either create a popup window or replace an existing one you might have created already and DestroyWnd() will close the currently open popup window.

CreateWnd() takes four parameters:

file = URI of the file to open
width = width of the created popup (in pixels)
height = height of the created popup (in pixels)
resize = boolean to specify if the popup is to be resizable

DestroyWnd() takes no parameters.

NOTE: If you repeatedly call CreateWnd() without destroying the current popup prior to each call it will replace the current popup. This is by design because I dislike (as many do) having more than one popup at a time from a webpage.

Example

<script language="JavaScript" src="popup.js"></script>
<body>
    <a href="javascript:CreateWnd('../somefile.html', 250, 200, true);"><BR>         Open Window</a>
</body>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jeremy Falcon

Software Developer (Senior)
Enta USA, LLC
United States United States

Member

Jeremy finds it odd to mention himself in the third person, but alas, since nobody else can relish in the delight of Jeremy's marvelous accolades on this page, he must. And since embellishment is the way of self-centric, third-person style of writing in any good piece, it will be accepted as Jeremy's duty to master the sublime art of conceit.
 
Jeremy has conquered cancer just by writing five lines of code. Unfortunately, the government disallows that code to be revealed to the populous. Jeremy also commands time and space with his facial hair. Jeremy thrice resurrected the dead by using undocumented APIs. Jeremy can read your mind too, simply because that's just how über Jeremy is.
 
What, you don't believe that? Ok, take two...
 
Jeremy is someone who understands the importance of doing his part in giving back to the online community at large. He has been tinkering with electronics and computers in general since circa 1986, but he has studied development since 1994. Over the years he has acquired somewhat of a diverse skill set - which ranges from graphics, to technician, to programmer.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralPopup Window PinmemberTheOtherJoJo12:05 11 May '05  
GeneralRe: Popup Window PinmemberJeremy Falcon10:26 24 Feb '06  
Generalyour awesome "centered popups" script PinmemberTact762616:58 18 Nov '03  
GeneralRe: your awesome "centered popups" script PinmemberJeremy Falcon10:28 24 Feb '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 12 May 2002
Article Copyright 2002 by Jeremy Falcon
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid