|
First, copy this script into the <HEAD>
<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
return false;
}
//-->
</SCRIPT>
For now we'll skip the details of how the script works, (see Under the Hood: Details of the Popup Script for a line-by-line description), and move to the next step. The script above opens the popup, but something needs to run the script. The most common situation is that the script is run when the user clicks on a link. A link like the following would run the script:
<A HREF="popupbasic.html" onClick="return popup(this, 'notes')">my popup</A>
which creates this link:
Most of the link is as usual. The URL of the page being linked to is in the
HREFonClickpopup() -- 'notes' -- indicates name of the popup window. Every popup window should have its own unique name. Be sure to put the name in single quotes ('').
So if you want to name the popup 'stevie'
then this would be the code:
<A HREF="popupbasic.html" onClick="return popup(this, 'stevie')">my popup</A>
onClickreturn or the script won't work. Be sure to start the command with return like this:
onClick="return popup(this, 'notes')"
To avoid this problem we have one more piece of code. This code does not go in the main page. Put the following code in the popup page itself. So, for example, the link above opens the page
"popupbasic.html", so the following code is in
"popupbasic.html", not the page you are reading right now.
<SCRIPT TYPE="text/javascript"> <!-- window.focus(); //--> </SCRIPT>
When the page in the popup is loaded, this script tells the browser to put the focus on the popup. This means that the popup comes to the front every time.
That's all the basic pieces to a popup. Everything from here out is a variation on this theme.
Copyright 1997-2002 Idocs Inc. Content in this guide is offered freely to the public under the terms of the Open Content License and the Open Publication License. Contents may be redistributed or republished freely under these terms so long as credit to the original creator and contributors is maintained.