RobG wrote:
A cookie will not help, all it will tell you is that your script noticed
that a window was opened at some time in the past, it can't tell you if
the window is still open. Nor does the absence of the cookie (or the
presence of a cookie saying the window was closed) mean that the window
isn't open (the opener may have been closed before the child window).
When I suggested cookies I was thinking that the child window would
control the cookie, not the opener. The quick test case below should
demonstrate the idea, it works on IE6 and Mozilla 1.7 and probably other
browsers (but not Opera, because they've always refused to trigger
onunload events when the page is closing).
--- winopen.html ---
<script type="text/javascript">
function Get_Cookie(name) {
if(typeof document.cookie == "string"){
var start = document.cookie.indexOf(name+"=");
var len = start+name.length+1;
if ((!start)&&
(name != document.cookie.substring(0,name.length))){
return null;
}
if (start == -1) return null;
var end = document.cookie.indexOf(";",len);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(len,end));
}else{
return "";
}
}
function op(a){
window.open(a.href, a.target);
return false;
}
</script>
<a href="wintest.html" target="foo" onclick="return op(this);">
Open Foo
</a>
<a href="#" onclick="alert(Get_Cookie('foo')); return false;">
is Foo open?
</a>
---
--- wintest.html ---
<script type="text/javascript">
function Set_Cookie(name,value,expires,path,domain,secure) {
if(typeof document.cookie == "string"){
document.cookie = name + "=" +escape(value) +
( (expires) ? ";expires=" + expires.toGMTString() : "") +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
( (secure) ? ";secure" : "");
}
}
window.onload=function(evt){
Set_Cookie("foo", "Popup is open");
}
window.onunload=function(evt){
Set_Cookie("foo", "Popup is closed");
}
</script>
---
The cookie functions are taken from the FAQ notes. Am I missing something?
Regards,
Yep.