make window not pop to back

E

Eric Osman

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>
 
D

Dom Leonard

Eric said:
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>
 
R

Randell D.

Eric Osman said:
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

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>
 
D

Dom Leonard

[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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top