By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,667 Members | 2,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,667 IT Pros & Developers. It's quick & easy.

make window not pop to back

P: n/a

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>

Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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>

Jul 20 '05 #2

P: n/a
"Eric Osman" <er*******@rcn.com> wrote in message
news:3F**************@rcn.com...

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>


Jul 20 '05 #3

P: n/a
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
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.