(Last Updated 11/1/98)



Java Script PopUp Window II



Pop-Up windows have many ways they can be used. The previous page illustrated their use as links activated by mouse actions. This page shows their use in providing an illusion of activity for long load pages. In the example shown, the window is activated by code located at the top of the page just after the page title is written. (Remember, HTML is processed line by line in the order its written. Therefore, this code has to be at the beginning of the page to be useful. It could also have been written as a function in the header of the page and activated by an
"onLoad=popUpWindowFunctionName()"
command in the BODY tag.)


(Picture drawn by DeAnna Krusman.)
I'm just watching this time.



The code to produce the effect is:
<SCRIPT LANGUAGE="Javascript">

width1 = 150 + 50
config='directories=no,status=no,menubar=no,width='+width1+',height=150'
config += 'toolbar=no,location=no,scrollbars=no,resizable=no'

pop = window.open ("","pop",config)

pop.document.write('<');
pop.document.write('/SCRIPT><BODY BGCOLOR=blue TEXT=gold>');
pop.document.write('<CENTER><B><H2>Welcome Friends</H2></B></CENTER>');
pop.document.write('<CENTER><FONT COLOR=white><B><H3>Please Wait... While This Page Loads</H3></B></CENTER>'); pop.document.write('<CENTER><B><H6>This Window Will Close Itself...</H6></B></CENTER>');
pop.document.write('</BODY>');
</SCRIPT>
The most interesting item seen in this script is the use of variables. The list of window propertities is defined in variable, "config", and placed above the "window.open" statement. (All Java Script variables MUST be defined before they are referenced.)

Additionally, one of the propertities, the window width, was put in as a variable, "width1".
This use of variables was obviously not needed here and was done only to show it is possible to have the scripts change dynamically. Although this case can hardly be called dynamic, it is easy to see the possibilities available. Scripts can adapt themselves to the client's platform, browser, or JavaScript version; or as a response to some other event such as the client's previous location, the data in a cookie, or how the script was initiated. The use of variables and conditional choice (if ... then ... else ...) statements provides much of the power of Java Script.



In case anyone is wondering, the "+=" is a shorthand operator that has gotten popular recently. The equation x += y means: for numbers: add y to x and assign the rsult to x
for strings: concatenate string y to the end of string x and assign the result to string x


Contact Carl Paulson with questions,
or Visit my pages.