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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing another window only if it's open 2

Status
Not open for further replies.

fischadler

Programmer
May 31, 2002
258
MT
Hi I am using the code below to open a pop up window.
Code:
<script>
<!-- Hide from old browsers
function winopen(PageURL){
  window.open(PageURL, 'NewWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,
copyhistory=yes,width=750,height=400,left=0,top=0')
}
// -->
</script>

<tr onMouseOver="this.bgColor='#C0C0FF';" onMouseOut="this.bgColor='#FFFFFF';" style="cursor: hand"

ONCLICK="NewWindow.close(); return false; winopen('mypage.asp')">

The problem with that is that if the pop is not already open, I will get an error (NewWindow is not yet defined) and nothing happens. The reason I want to close the pop up before opening another one is that otherwise, if the pop is in the background, it will remain there and people might not necessarily realise it's contents were changed. So I thought that closing it and popping it up again will bring it to the front. Another option would be to 'simply' make the pop up window come to the front after it is loaded or it's contents changed. But I don't know how to do that.

-Fischadler
 
I'm so green in Javascript that I don't even know what "return false" does. However the problem has nothing to do with this because the error occurs in the preceding line and removing "return false" has no effect.

-Fischadler
 
Do this rather.
[tt]<script>
<!-- Hide from old browsers
[red]var owin;[/red]
function winopen(PageURL){
[red]owin=[/red]window.open(PageURL, 'NewWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,
copyhistory=yes,width=750,height=400,left=0,top=0')
}
// -->
</script>

<tr onMouseOver="this.bgColor='#C0C0FF';" onMouseOut="this.bgColor='#FFFFFF';" style="cursor: hand"
ONCLICK="[red]if (owin && !owin.closed) owin.close()[/red]; winopen('mypage.asp')">
[/tt]
 
Or on you PageURL, set focus on page load like this:

<body onload="self.focus()">

This way, when you open the page, it always get focused and showed on top.
 
Thanks Fischadler. There are also alternative to get the same result without explicitly closing the pop up window. Such as this.
[tt] onclick="if (owin && !owin.closed) {owin.location.href='mypage.asp'} else {winopen('mypage.asp')};"[/tt]
With m/c nowadays, there seems to be just as simeless. Maybe only focus aspect which behaves a bit different.
 
Tsuji,
I did not try your second suggestion, but from what I can understand (correct me if I'm wrong), if the pop up is open, it will refresh the contents. However, if it is behind the window that is calling it, it will remain there. I have a usually maximised window with a list. Clicking on a row shows the full details in a smaller pop up but the main maximized window with the list would still be visible in the background. What was happening was, when someone clicked on a visible row without first closing the pop up, the main window would get the focus and come on top while the pop up was updated but sent behind the maximized window.

Kendel's suggestion also solves my problem so a star goes to you too.


-Fischadler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top