Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript window opening behind parent window

Status
Not open for further replies.

peterswan

Programmer
Sep 25, 2002
263
US
Hello,

I'm opening a popup window with Javascript as follows:

<script language="Javascript">
function openWin() {
window.open('somePage.html', 'newWindow', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=375,height=325');
}
</script>

<a href=openWin()">click to open window</a>

Usually the window opens fine, in front of the parent window, but sometimes it opens up behind the parent window, and users don't know that the window opened up at all.

This only occurs intermittently, and only in IE7. I have never encountered this problem in IE6. I do not have any idea what is causing this problem because I seem to be doing the same thing each time. I'm clicking on the same link, nothing different than before, nonetheless, on occasion the new window will not move to the front unless the user finds the window and brings to the front.

Is there some sort of workaround I can add to the code? is there some sort of IE setting I can change to fix this?

Thanks,

Peter [smile]
 
Should be in the JavaScript Forum: forum216

But to answer your question, the window.open function returns a handle to the newly opened window. By assigning that handle to a variable instead of letting it slip into the ether, one can subsequently call the window's [tt]focus()[/tt] method to ensure it comes into view... as well as other neat things like close the popup when it's no longer needed... you do want to do that don't you?
to wit:
Code:
 var popupHandle = window.open('somePage.html', 'newWindow', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=375,height=325');
 popupHandle.focus();

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Enable Apps
 
Hi dwarfthrower,

Thanks for the advice. I added the new code,
but the window still only opens in front of the
browser sometimes, and not in others.

I wasn't getting this problem at all in IE6,
that's why I believe this is a browser related
issue.

Here's how my code looks now:

<script language="Javascript">
function openWin() {
var popupHandle = open('somePage.html', 'newWindow', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=375,height=325');
popupHandle.focus();
}
</script>

If this code displays outside of the window on
this forum, you can copy by dragging your mouse
along the text and then copy and paste into
Notepad. I'm not sure why this viewing window
isn't displaying all of my post.

Thanks for any help,

Peter [smile]
 
Could this be a Windows issue?

I noticed that Alt + Tab to redisplay
a program only works sometimes, however,
not always. It's as if the command from
the browser to display the new window
worked fine, but the process of displaying
the new window on my computer does not
work correctly every time.

Is there some setting on my computer that
may fix this?

Thanks,

Peter
 
In your somepage.html add the following inside the head tag :

Code:
<script type="text/javascript">
<!--
window.focus();
//-->
</script>

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top