make window not pop to back

Discussion in 'Javascript' started by Eric Osman, Jul 18, 2003.

  1. Eric Osman

    Eric Osman Guest

    Hi,

    When I run the following html file on netscape, and the button is
    clicked, the new window pops BEHIND all my other windows.

    How can I easily fix this html file so the window comes up in front
    (like a standard alert window would) ?

    Thanks. /Eric

    Here's the html file (feel free to copy-paste it to try it) :

    <html><head><script><!--
    function showWin() {
    var popWin=window.open("","Pop","width=600,height=100,resizable=yes");
    var hh="<HTML><HEAD><TITLE>Answer</TITLE></HEAD>";
    hh+="<BODY><form><textarea cols=30 rows=3>You may highlight or edit";
    hh += "</textarea></form></BODY></HTML>";
    popWin.document.write(hh);
    popWin.document.close();
    }
    // --></script></head><button type=button
    onmousedown='showWin();'>Press to create popup window</button></html>
     
    Eric Osman, Jul 18, 2003
    #1
    1. Advertising

  2. Eric Osman

    Dom Leonard Guest

    Eric Osman wrote:
    >
    > Hi,
    >
    > When I run the following html file on netscape, and the button is
    > clicked, the new window pops BEHIND all my other windows.
    >
    > How can I easily fix this html file so the window comes up in front
    > (like a standard alert window would) ?


    Page below tested under Moz 1.3. Modifications include closing the
    answer window if it is already open and getting the onload event of the
    answer window to call focus. Simple call from onload didn't work, so
    decoupled event processing through a timer. Tested in Moz only - would
    need to test in more browsers before hitting the web :)

    HTH
    Dom
    ============

    <html><head><script><!--

    var popWin;
    function showWin() {
    if(popWin&&!popWin.closed)
    popWin.close();
    popWin=window.open("","Pop","width=600,height=100,resizable=yes");

    var hh="<HTML><HEAD><TITLE>Answer</TITLE>";
    hh+='<script type="text/javascript">';
    hh+='function raise(){self.focus();}';
    hh+='function decouple(){setTimeout("raise()",50);}';
    hh+='window.onload=decouple;<\/script>';
    hh+="</HEAD>";

    hh+="<BODY><form><textarea cols=30 rows=3>You may highlight or edit";
    hh += "</textarea></form></BODY></HTML>";
    popWin.document.write(hh);
    popWin.document.close();
    }
    // --></script></head><button type=button
    onmousedown='showWin();'>Press to create popup window</button></html>
     
    Dom Leonard, Jul 19, 2003
    #2
    1. Advertising

  3. Eric Osman

    Randell D. Guest

    "Eric Osman" <> wrote in message
    news:...
    >
    > Hi,
    >
    > When I run the following html file on netscape, and the button is
    > clicked, the new window pops BEHIND all my other windows.
    >
    > How can I easily fix this html file so the window comes up in front
    > (like a standard alert window would) ?
    >
    > Thanks. /Eric
    >
    > Here's the html file (feel free to copy-paste it to try it) :
    >
    > <html><head><script><!--
    > function showWin() {
    > var popWin=window.open("","Pop","width=600,height=100,resizable=yes");
    > var hh="<HTML><HEAD><TITLE>Answer</TITLE></HEAD>";
    > hh+="<BODY><form><textarea cols=30 rows=3>You may highlight or edit";
    > hh += "</textarea></form></BODY></HTML>";
    > popWin.document.write(hh);
    > popWin.document.close();
    > }
    > // --></script></head><button type=button
    > onmousedown='showWin();'>Press to create popup window</button></html>
    >


    Ah! Hope this helps you... I'm a newbie at javascript and I save some
    responses to disk that I think I might want to use at some point... read the
    post below (I think by a chap called Grant Wagner) and I hope it makes some
    sense to you...
    randelld


    > > Grettings:
    > > I have a website where clicking on an image will spawn a pop-up window
    > > that will show a larger version of the image. However, if the user
    > > clicks on an image, it pops up in its own new browser window, and then
    > > the user clicks on the old browser window, the new pop-up window will
    > > revert back to the background and no window will pop-up if the user
    > > clicks on a new image. I know that I am bombarded with pop-ups
    > > everytime I search the web. Some of these pop-ups just run in the
    > > background and I only see them after I have closed all of my other
    > > browser windows. Is there a reverse of this? Can I embed some code in
    > > the onload event to bring the pop-up browser window to the top if the
    > > page reloads with a different image?

    >
    > Just add an
    > nameOfPopUpWindow.focus();
    > to your links.
    >
    > If you want to be nasty (which you do not want to be, of course), you can
    > put a
    >
    > nameOfPopUpWindow.onblur="nameOfPopUpWindow.focus()";


    If he puts that, nothing will happen onblur. Event handlers aren't strings,
    they are references (pointers) to functions.

    nameOfPopUpWindow.onblur = nameOfPopUpWindow.focus;

    might do it, but I also have a problem with you saying "nameOfPopUpWindow",
    because you don't call the focus() method on a window's name, you call it on
    the reference (pointer) to the window.

    > and your pop up will always remain in the foreground. However, the

    original
    > window cannot be accessed anymore now.


    OP: To make it do what you seem to be asking, make the <body> tag of the
    popup
    window look like:

    <body onload="window.focus();">
    <!-- your popup content goes here -->
    </body>
     
    Randell D., Jul 19, 2003
    #3
  4. Eric Osman

    Dom Leonard Guest

    Dom Leonard wrote:
    > Eric Osman wrote:
    >>
    >> When I run the following html file on netscape, and the button is
    >> clicked, the new window pops BEHIND all my other windows.
    >>
    >> How can I easily fix this html file so the window comes up in front
    >> (like a standard alert window would) ?

    >

    [original repeated for cut and paste]

    <html><head><script><!--
    function showWin() {
    var popWin=window.open("","Pop","width=600,height=100,resizable=yes");
    var hh="<HTML><HEAD><TITLE>Answer</TITLE></HEAD>";
    hh+="<BODY><form><textarea cols=30 rows=3>You may highlight or edit";
    hh += "</textarea></form></BODY></HTML>";
    popWin.document.write(hh);
    popWin.document.close();
    }
    // --></script></head><button type=button
    onmousedown='showWin();'>Press to create popup window</button></html>


    Hi Eric, sorry to answer my own post, but my previous response was
    bugging me because I hadn't needed to go to such lengths before.

    Using your posted code above, there is something very strange about the
    BUTTON element behavior in Mozilla - after opening the window, mouse
    over and out of the BUTTON element causes button up and down motion as
    if processing of the entire click sequence has been disrupted by opening
    the window using mousedown. I'm not about to submit a bug report, but
    strongly suspect you are looking for workaround code for this behavior.

    The first recommendation is to change the event used to call showWin
    from onmousedown to onclick. Most of the problems go away immediately,
    with the added advantage the user can cancel click action by dragging
    the mouse out of the button.

    If onmousedown must be retained as the trigger, then changing the BUTTON
    element to an INPUT element (leaving type the same) improves things
    greatly under Mozilla.

    The general observation remains that generating the same page a second
    time will not bring it to the front if the user has not closed it since
    opened. This is where closing an already opened window, as performed in
    the previous post, can be useful.

    Hope this is of slightly more use :)
    Cheers,
    Dom
     
    Dom Leonard, Jul 20, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Microsoft News
    Replies:
    2
    Views:
    1,129
    Microsoft News
    Jan 27, 2005
  2. Shiperton Henethe
    Replies:
    17
    Views:
    5,501
    Deirdre Saoirse Moen
    May 21, 2004
  3. ram_kri
    Replies:
    4
    Views:
    10,414
    ram_kri
    Sep 1, 2006
  4. samppi
    Replies:
    27
    Views:
    553
    David A. Black
    Dec 5, 2007
  5. Madame Blablavatsky
    Replies:
    8
    Views:
    208
    Dr John Stockton
    Sep 16, 2005
Loading...

Share This Page