|
This script allows you to open a secondary window with a
browser much like you would normally do with the operating system you are using. This
second window can be used to provide details about a particular item, instructions on how
to properly use a form, etc. Click below for a quick sample, then take a look at the scipt
that made it possible.
<script
language="JavaScript">
<!--
function winOpen( ) {
sample=open("","Testing",'location=0,status=0,toolbar=0,width=200,height=200')
var sd = sample.document
sd.open( );sample.focus(
)
sd.write("<body bgcolor='#FFFFFF'>");sample.focus( )
sd.write("<center><h2>Pretty Neat,
huh?</h2></center>");sample.focus( )
sd.write("<center><form>");sample.focus()
sd.write("<input type='button' value='Back to Form'
onclick='window.close( )'>");
sd.write("</form></center></body>");sample.focus( )
sd.close( );
}
//-->
</script>
- The following button can be placed anywhere in the page.
Note that the above function is run when a user clicks the button created below.
<form><center>
<input type="button" value="Open Sesame" onClick="winOpen(
)">
</center></form>
- The script begins by declaring and defining the function
winOpen( )
- The window name is to be called "sample", and its
parameters are specified. In this case, the first parameter is left blank
("") because it is a new document we are creating. The document MUST have
a title; here it called "Testing". Finally, the specifications for the
window itself, including width, height, location, and whether or not the location, status
bar or toolbar will be visible. It's very important NOT to put any spaces between
the items listed here.
- Finally, the document.write feature is used to write to the
new window. You can use regular HTML in the parentheses, but it has to follow the
following format:
sample.document.open( );sample.focus( )
sample.document.write("<HTML tags
here>");sample.focus( )
sample.document.close( );
- Don't forget that since you already use double quotes on the
outside, anything inside MUST use single quotes
( e.g., sample.document.write("<img src='sample.gif'>")
Back to Web Tips |