SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbie, retain window active HELP !!!

    I'm sure there is a very easy solution to my problem that I am overlooking. I am new to Javascript. I want to create a screen with several links, each link needs to pull up a seperate window. The 'name' of the window can be the same. each time another link is clicked I want it to load into the second window for each case. So there will be no more than two window at a time. THE BIG CATCH is I want each time a link is click and the second window loads, I then want it to be the active window. Here is my last code which I was tryint to close it then reload it. There is probably an easier way ...PLEASE HELP !!!!

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <head>
    <title>burgers</title>
    <script type="text/javascript">
    var url
    var newwindow

    function popwindow(url)
    {
    newwindow.close();
    window.open('url','newwindow','width=400,height=200')
    }

    </script>
    </head>
    <body>
    <script type="text/javascript">


    <INPUT type="button" value="Win 1" onClick="popwindow(Test for window1.html)">

    <INPUT type="button" value="Win 2" onClick="popwindow(Test for window2.html)">
    </script>
    </body>
    </html>

  2. #2
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Devon, UK
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't need JS for this unless you want to resize the popup window:

    <a href="page1.html" target="window2">link</a>
    <a href="page2.html" target="window2">link</a>

    That will also work without JS enabled. You could then add progressive enhancement to size the second window.

    But, do you really, really need a popup window? They're very irritating, and I'd suggest you only use them if absolutely necessary.

  3. #3
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, and yes I need it as a pop up ...it is for a project at work ...not to be published on www. ...even in your example the same problem exist. Yes it will load the same window with the new information however that new window will not be active... because the user had to click on the link on a seperate window.

  4. #4
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Devon, UK
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK - use window.focus(). In your example...

    Code:
    var win = window.open(...args...);
    win.focus();


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
  •