Results 1 to 5 of 5

Thread: Identifying Popups

  1. #1
    Join Date
    Aug 2011
    Location
    Rep Of Ireland
    Posts
    126
    Thanks
    24
    Thanked 3 Times in 1 Post

    Default Identifying Popups

    Using the following to create a popup window for an application:-

    Code:
    <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...

    Code:
    <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?.
    Last edited by jscheuer1; 11-05-2011 at 05:20 AM. Reason: Format

  2. #2
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Write two separate functions, or amend your single function to accept size and width parameters.

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    The answer to your question:

    Quote Originally Posted by Webiter View Post
    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):

    Code:
    <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:

    Code:
    <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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Aug 2011
    Location
    Rep Of Ireland
    Posts
    126
    Thanks
    24
    Thanked 3 Times in 1 Post

    Default

    If I write a separate function and call it function popup1() is that correct!

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Yes that's right.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •