HighDots Forums  

Closing a popup from a different page

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Closing a popup from a different page in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
fiziwig
 
Posts: n/a

Default Closing a popup from a different page - 11-01-2006 , 07:39 PM






I'm pretty new to JS so this is probably a stupid question, but I can't
seem to find the answer.

I have a page that opens a popup window. That popup needs to stay open
as the visitor clicks from page to page on my site. But then when the
visitor gets to the last page I want that page to close the popup
onUnload.

I tried passing the window object in a cookie but that doesn't seem to
work. I can read the cookie into my window object variable alright, but
the object doesn't seem to have the right properties. This test code
for looking at the cookie data pops up the alert "popup exists", but
does not pop up any of the other alerts, so havePop.location clearly
doesn't have a legitimate value.

What am I doing wrong?

Thanks,

--gary

function createCookie(name,value) {
var date = new Date();
date.setTime(date.getTime()+60*60); // set a short-time cookie
var expires = "; expires="+date.toGMTString();
document.cookie = name+"="+value+expires+"; path=/";
}
var windowHandle="";
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return
c.substring(nameEQ.length,c.length);
}
return null;
}
function openWindow() {
windowHandle=window.open('_popup.php',
'popper','width=400,height=550,resizable=0,toolbar =0,location=0,directories=0,status=0,menubar=0,scr ollbars=1');
createCookie('pop',windowHandle);
}
function closeWindow() {
windowHandle=readCookie('pop');
if (windowHandle!="") {
alert("popup has properties");
if (windowHandle.location) {
alert("popup has location");
if (!windowHandle.closed) {
alert("closing popup");
windowHandle.close();
}
}
}
}


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.