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

closing pop-up windows

Status
Not open for further replies.

awesomebeats

Technical User
Nov 29, 2001
25
US
i'm using this code to try to redirect a window named 'active'. i get an error saying 'active' is undefined. my resources say i should be able to refer to the window by its name.

if (active.closed) {
top.location="../index.cfm";
} else {
active.location="close.cfm";
}

this is the code i open the window with:
window.open('active.cfm','active','width=250,height=175,scrollbars=no, resize=yes');

why can't i refer to the window by its name or can i and am i just doing something wrong.thanx

awesomebeats
 
You could try making the the window name a variable

var newWin = window.open('active.cfm','active','width=250,height=175,scrollbars=no, resize=yes');

then refer to it like
if (newWin.closed) {
top.location="../index.cfm";
} else {
newWin.location="close.cfm";
}

I hope that helps
Roj
 
the thing is i open the window 'active' on another page and i'm now trying to run the if statement from another pop-up. Maybe the best thing to do would be do to just tell you why i'm doing this in the first place. I have a pop-up window named 'active' that has a close button. when you press this button it goes to logout.cfm and logs the user out. logout.cfm the closes 'active' and tells the main page to go to index.cfm. however, many users are just hitting the x instead of properly closing so i'm trying an onbeforeunload parameter where i then open a new window with logout.cfm. i now need to close the 'active' window redirect the main page to index.cfm and then close the 'logout' window. if there were a way to do something where before the window closed it went to logout.cfm real quick that would solve all my problems. i've tried using a location thing in the onbeforeunload but that doesn't work. any help please! thanx.

awesomebeats
 
try this
<body onbeforeunload =&quot;window.open('logout.cfm','new')&quot;>
I tried it with IE and it will open the second window as the first closes.

Roj
 
roj,

that works ok i put a close link in 'active' and then before it closes i get a new window to open that logs them out. however, how do i redirect the main page, the one that opened 'active', from the newwin.

alexi
 
Sorry forgot about that part. So we change your onbeforeclose section.

Set the onbeforeclose=&quot;closeSwithch()&quot;

then in the head of the active page you can put this.

function switchClose(){
window.open('log_out.html','new');
window.opener.location.reload(&quot;redirect.pagename&quot;);
}
So now when the user closes the window this function will open the log out page and also redirect the main page to another page for you.

Roj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top