Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Open Window

  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Open Window

    Scenario:
    I have a link that when clicked opens a new/2nd window. When I click another link in the 1st window, I would like for that link to open in the 2nd window. The code below is what I'm using but it continues to open new windows when I click a link:

    <html>
    <head>
    <title>Untitled Document</title>
    <script language="JavaScript">
    <!--

    function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
    }
    //-->
    </script>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <a href="javascript:;" onClick="MM_openBrWindow('http://www.espn.com', 'win2','width=450,height=450,resizable,scrollbars')" >ESPN</a>
    <br><br>

    <a href="javascript:;" onClick="MM_openBrWindow('http://www.cnn.com', 'win2','width=450,height=450,resizable,scrollbars')" >CNN</a>

    <body>
    </body>
    </html>


  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well your problem is window.open() opens a new window everytime. What you want to do is something like this:
    Code:
    <script language="JavaScript">
    <!--
    var win = null;
    function MM_openBrWindow(theURL,winName,features) { //v2.0
     if(win == null) {
      window.open(theURL,winName,features);
     }
     else {
      win.location.href = theURL;
     }
    }
    //-->
    </script>
    Let me know how that works out for you.

    Sadiq.

  • #3
    New Coder
    Join Date
    Jun 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unfortunately Sadiq, this didn't work either. It is still opening two separate windows.

    Can you think of anything else...

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oops! Missed a small but very important detail:
    Code:
    <script language="JavaScript">
    <!--
    var win = null;
    function MM_openBrWindow(theURL,winName,features) { //v2.0
     if(win == null) {
      win = window.open(theURL,winName,features);
     }
     else {
      win.location.href = theURL;
     }
    }
    //-->
    </script>
    That should do the trick.

    Sadiq.

  • #5
    New Coder
    Join Date
    Jun 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you Thank you Thank you so very much Sadiq that works but there is one small problem. After the 2nd link is clicked, the window then hides behind any other open window. How can I make the focus the same as the when the 1st link is clicked?

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sure can:
    Code:
    <script language="JavaScript">
    <!--
    var win = null;
    function MM_openBrWindow(theURL,winName,features) { //v2.0
     if(win == null) {
      win = window.open(theURL,winName,features);
     }
     else {
      win.location.href = theURL;
      win.focus();
     }
    }
    //-->
    </script>
    That should do the trick for ya.

    Pretty quick replies, eh? Kinda funny..

    Sadiq.


  •  

    Posting Permissions

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