Re: make window not pop to back

Giganews Newsgroups
Subject: Re: make window not pop to back
Posted by:  Dom Leonard (doml.removethis@senet.andthis.com.au)
Date: Sat, 19 Jul 2003

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>

Replies

In response to

make window not pop to back posted by Eric Osman on Fri, 18 Jul 2003