Pop-up windows can be really annoying. In general people don't like it when a whole bunch of unasked-for windows appear when they click on a link (or worse yet, simply mouse-over a hot spot, or try to close a window). And yet, when used responsibly, pop-ups can be quite handy. One of the great advantages to javascript pop-ups is that you (the designer) can set the size of the window to be opened. You can also control (to an extent) whether or not the pop-up contains scroll bars, tool bars and other "extras." However, this method requires the user to have javascript turned on (and pop-up blockers turned off), so it's not foolproof. Nevertheless, I present it here for your edification. Down at the bottom I will provide links to some sites that have clever modifications on pop-ups.
<a href="#">Click here</a>
<script type="application/javascript" language="javascript">
<!--
function popup(theURL,winName,features) {
window.open(theURL,winName,'width=300,height=300');
}
-->
</script>
Some explanations are in order. First of all, a function is a bit of code that contains a specific instruction to be carried out. Functions can be used multiple times within a document; this way if I have 50 links opening pop-ups I don't have to write 50 separate scripts; I simply attach this function to each one. We're calling this function popup. "Popup" is not a special term it's just a name we've chosen to identify this particular function; we could call it "bob" or "fred" if we wanted.
Functions often contain variables; these are things that are likely to change (or "vary") every time we use the function in our code. In this case there are three variables: theURL, winName, and features. The first one, "theURL," will contain the url of the page we are opening (we'll assign that in the link itself in a few moments). The second one,"winName," will be the name of the window we are opening; names are important if we want to target a link into a particular window (more on that later). The third one, "features," will contain all of the parameters we will set for the window (like size, scrollbars, etc.).
The next line contains a specific javascript command: window.open(). This command does just what it says, opens the new window. In the parenthesis we can assign our variable values. Note that we leave theURL and winName the same, this is because we will assign those values in the link below. However, in place of the third variable I've set a size: 'width=300,height=300'. Any and all parameters need to be inside the single quotes and separated by commas—no spaces. (One aside, I have seen folks use standard quotes (") in place of the single quotes(') and those seem to work just as well; perhaps a programming whiz can tell me what the difference, if there is one, is).
<a href="#" onClick="popup('popUpPage1.html','newWindow1')">Click here</a>
The onClick command is triggered by a mouse click. Other options include onMouseUp, onMouseDown, onMouseOver, etc.
When the user clicks, that will trigger the function called "popup" that we wrote above. In the parenthesis we assigned the values we did not assign above, namely the url of the link followed by the name of the window we are opening. Once again, there is nothing magical about the window name; I just made it up.
window.open(theURL,winName,'width=300,height=300,toolbar=yes,location=yes,
status=yes,menubar=yes,scrollbars=yes,resizable=yes);
Giving these features a "yes" values turns them on. To hide them, use "no." Once again there should be no spaces separating the features.
Warning: if you copy and paste the code above, remove the break between "location=yes," and "status=yes." There should be no spaces or breaks in the line (I had to add a return in order to fit the code on this page).
function popup(theURL,winName,features) {
window.open(theURL,winName,features);
}
And the link will now look like this:
<a href="#" onClick="popup('popUpPage1.html','newWindow1','toolbar=no,location=no,
status=no,menubar=no,scrollbars=no,resizable=no,width=300,height=300')">
Click here</a>
4 pts |
Went far above & beyond & made something special. |
3 pts |
Went above & beyond (tried theme & variation, etc.). |
2 pts |
Did the minimum. |
1 pts |
Incomplete or not functioning properly. |
0 pts |
Poor showing; mostly incomplete or full of errors. |