Results 1 to 17 of 17

Thread: how to get a window to show on top?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537

    how to get a window to show on top?

    I have a parent window that opens a new window.

    if the new window is already open but minimized or behind the parent I want to bring the focus to that window. (bring it to the front)

    Code:
    <script>
    if(newWin) // if the newWin exists...
    {
    newWin.focus; //bring it to the front
    }
    {
    nextWin=window.open('help_page.asp','newWin','status=no,resizable=yes,scrollbars=yes,location=no,left=170,top=200,width=700,height=570,menubar=no');
    }
    </script> "

    This seems logical but doesn't give me the results I want.

    I get an error saying newWin is not defined...?


    any suggestions are appreciated.

    Thanks
    pnj

  2. #2
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

  3. #3
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    I think you're just missing the () after focus:

    Code:
    newWin.focus(); //bring it to the front
    If that doesn't work then I think you need to use nextWin instead of newWin for the focus function.
    Last edited by Rick Bull; Sep 27th, 2002 at 01:45 PM.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    cool.

    thanks

    I did try changing the code to newWin vs. nextWin and got the same error message.
    pnj

  5. #5
    Lively Member
    Join Date
    Jul 2002
    Location
    Gateshead, UK
    Posts
    101

    focus()

    Doesn't focus() work? If not, that it must be something else... you mustn't forget the function parantheses.
    <% Session("OwNeD")=True %><html><body>Blah... <%="Now get your ass back to the twilight zone..."%></body></html>

  6. #6
    Lively Member
    Join Date
    Jul 2002
    Location
    Gateshead, UK
    Posts
    101

    Aha!

    Originally posted by pnj
    Code:
    <script>
    if(newWin) // if the newWin exists...
    {
    newWin.focus; //bring it to the front
    }
    { <--- Syntax error here
    nextWin=window.open('help_page.asp','newWin','status=no,resizable=yes,scrollbars=yes,location=no,left=170,top=200,width=700,height=570,menubar=no');
    }
    </script>
    I can't believe I didn't notice this earlier... don't you mean "} else {"?
    <% Session("OwNeD")=True %><html><body>Blah... <%="Now get your ass back to the twilight zone..."%></body></html>

  7. #7
    Lively Member
    Join Date
    Jul 2002
    Location
    Gateshead, UK
    Posts
    101

    Am I right?

    Well, am I? Or is that just another shorthand way of writing "if" conditionals...?
    <% Session("OwNeD")=True %><html><body>Blah... <%="Now get your ass back to the twilight zone..."%></body></html>

  8. #8
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    I think the { and } should just be removed shouldn't they as you want the page to change even if the window is already open, so calling window.open should do that. I think you can leave the { and } there anyway can't you? Doesn't it just make the enclosed statements sort of equal to one statement?

  9. #9
    Lively Member
    Join Date
    Jul 2002
    Location
    Gateshead, UK
    Posts
    101

    Try this...

    <script>
    if(newWin) newWin.focus(); //bring it to the front

    // Open next window, regardless of the previous window
    nextWin=window.open('help_page. asp','newWin','status=no,resizable=yes,scrollbars=yes,location=no,left=170,top=200,width=700,height= 570,menubar=no');
    </script>
    <% Session("OwNeD")=True %><html><body>Blah... <%="Now get your ass back to the twilight zone..."%></body></html>

  10. #10
    Lively Member
    Join Date
    Jul 2002
    Location
    Gateshead, UK
    Posts
    101

    hang on...

    It's saying that newWin isn't defined...? That's a bit odd, since the "if" conditional checks to see if the var exists, before it calls the focus() function - that's the whole point...
    <% Session("OwNeD")=True %><html><body>Blah... <%="Now get your ass back to the twilight zone..."%></body></html>

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    Code:
    var child = new Object(); 
    child.open = false;   
    
    
    if( !child.open ){	
    child = window.open("blank.htm"); 
    child.open = true;
    }else{
    child.focus();
    }
    ok, this is what the code looks like now.

    it still doesn't work however.....

    I get an error message from line 2 ?

    makes no sense to me...

    thanks for all your help everyone.
    pnj

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    ?
    ok,

    NOW it works.
    that was strange.....

    only it opens up a NEW window EVERYTIME.

    i only need the window to open once. it it's already open, bring it to the front....

    do I need to name the window?

    I tried the standard

    newWin= window.open(mypage.htm,'nameOfWindow') but it just put the nameOfWindow into the query string...
    so weird...

    thanks again
    pnj

  13. #13
    Lively Member
    Join Date
    Jul 2002
    Location
    Gateshead, UK
    Posts
    101

    Well...

    The 'nameOfWindow' string is the actual title/name of the new window...

    Let's get this straight:

    a) You want a parent popup window to be open first; if so than open a smaller child?

    b) If the parent isn't open/focused then open and focus() it...?
    Last edited by trojjer; Oct 1st, 2002 at 03:28 PM.
    <% Session("OwNeD")=True %><html><body>Blah... <%="Now get your ass back to the twilight zone..."%></body></html>

  14. #14
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Nooo...

    He wants the Parent to launch a new window (Client), but if the window has already been opened then it will simply bring that window to the front.
    Don't Rate my posts.

  15. #15
    Lively Member
    Join Date
    Jul 2002
    Location
    Gateshead, UK
    Posts
    101

    Ah

    It's clear now...

    Client page:
    Code:
    <script language="javascript"><!--
    if (!newWin) {var newWin=window.open(...); //Open new window
    }else{newWin.focus(); //focus window}
    --></script>
    This is almost exactly the same as before, I think, the only difference is that it checks to see whether the var newWin does not exist, as you know. It should work - dunno why it isn't for you... Try it though...

    P.S: Obviously, replace the "..." in window.open() with the window details...
    <% Session("OwNeD")=True %><html><body>Blah... <%="Now get your ass back to the twilight zone..."%></body></html>

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    so if i put the window attributes in like this
    Code:
    ('blank.htm','child','status=no,resizable=no,scrollbars=yes,location=no,left=170,top=200,width=300,height=270,menubar=no'); //used blank just for demo purposes
    in Netscape 7 it works. at least it opens the window with the attributes.
    but it won't bring it to the front if it's allready open.


    in IE 6 I get an Unterminated String constant...


    ?
    if I remove the attributes and test in IE and Netscape it opens a new window but won't bring it to the front if it's allready open.

    aarrg.
    pnj

  17. #17
    Lively Member
    Join Date
    Jul 2002
    Location
    Gateshead, UK
    Posts
    101

    This works...

    This works in IE, and it should work in NN with no conditionalising required. For an example of this script in action, it's on my site @ http://vacuum.virtualave.net/examples/js_windows.asp

    Or just click the "masked" links...
    Last edited by trojjer; Feb 9th, 2003 at 09:38 AM.
    <% Session("OwNeD")=True %><html><body>Blah... <%="Now get your ass back to the twilight zone..."%></body></html>

Posting Permissions

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



Click Here to Expand Forum to Full Width