A Self-Loading Pop-Up Window

(beginner)


     


This is probably the easiest JavaScript you'll find!

The easiest pop-up window pops up when the page loads, and does not require an on-click event to trigger it. It comes in handy when you want to make a special announcement that you don't want your visitors to miss. (example)

However, this is also the sort of window that, most annoyingly, opens on numerous commercial websites. People hate that sort of window, especially since they have no control over it's appearance: all they do is open a webpage, and there's the window! Therefore, use it judiciously. The information contained in such a window should be absolutely relevant to the visitor of the page: on a job site, it might list new job openings; on a theatre site, the present schedule of events; on a store site, the items on sale at the moment. It's also a good idea to give the visitor a chance to close the window right on screen, with a simple clickable link in the window itself. To achieve that, just place the following line of code inside and at the bottom of the window's contents:

<A HREF="javascript:window.close();">click here to close window</A>

This will create a link that closes the popup.

And here's the code for the window itself; just insert it between the <head> tags of your document:

<SCRIPT LANGUAGE="javascript">


<!--//
{
window.open("yourlink.html", "new", "resizable=no, width=400, height=320, scrollbars=no");
}
//-->


</SCRIPT>

For "yourlink.html", write the file name of the window you want to open.
You can change the dimensions of the window in the width and height lines: the dimensions given are in pixels; simply fill in the pixeldimensions of the window you want to create.
In addition, you can allow scrollbars if your content is greater than the window you have opened: simply set the scrollbars parameter to 'yes' instead of 'no'. You can also allow the user to resize the window, using the same method.

That's all there is to it: No code beyond that is required, since the window opens when the page loads, with no event handler necessary.