PDA

View Full Version : Identifying Popups



Webiter
11-03-2011, 12:55 AM
Using the following to create a popup window for an application:-


<script type="text/javascript">
function popup() {window.open('an application file', '','scrollbars=1,statusbar=0,resizable=0,width=450,height=580,left=450,top=80');}
</script>

Then the link to call the function...


<li><a href="javascript:popup()">Here is the popup window.</a></li>

I require to create another popup that will have different dimensions - how should this second function popup() be identified from the first one so that they can be attached to different links?. :o

clueful
11-05-2011, 02:23 AM
Write two separate functions, or amend your single function to accept size and width parameters.

jscheuer1
11-05-2011, 05:48 AM
The answer to your question:


how should this second function popup() be identified from the first one so that they can be attached to different links?

is, as clueful hints, just give each function a different name. However, here's a different approach to the problem (also hinted at by clueful):


<script type="text/javascript">
function popup(href, w, h){
open(href, '_blank','scrollbars=1,statusbar=0,resizable=0,width=' + w + ',height=' + h + ',left=450,top=80');
return false;
}
</script>
<li><a href="an application file" onclick="return popup(this.href, 450, 500;">Here is the popup window.</a></li>
<li><a href="another application file" onclick="return popup(this.href, 550, 600;">Here's another popup window.</a></li>

An additional thing to consider is that once you open a popup, unless it is closed, browsers will reuse it, but not resize it. If the target/name (highlighted in the above) is _blank or unique though, it will open a separate window. With _blank it will open a separate window each time either link is clicked, so you could end up with like 80 windows. You have separate windows for each link, but the total number of possible windows is endless. One could instead do:


<script type="text/javascript">
function popup(href, name, w, h){
open(href, name,'scrollbars=1,statusbar=0,resizable=0,width=' + w + ',height=' + h + ',left=450,top=80');
return false;
}
</script>
<li><a href="an application file" onclick="return popup(this.href, 'popup1', 450, 500;">Here is the popup window.</a></li>
<li><a href="another application file" onclick="return popup(this.href, 'popup2', 550, 600;">Here's another popup window.</a></li>

That way once one link is clicked, no matter how many times you click it, it will use the same window, but the other link will create its own, and will reuse it if it's clicked multiple times. So you end up with no more than two separate windows, and a separate window for each link.

Webiter
11-05-2011, 02:42 PM
If I write a separate function and call it function popup1() is that correct!

jscheuer1
11-05-2011, 05:06 PM
Yes that's right.