473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Determining whether a window is open

I have the following situation: Page A opens a window named 'foo'.
Page A then reloads itself. Is there a way for the reloaded Page A to
determine whether there is an open window named 'foo', *without*
calling window.open?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #1
9 3437
Christopher Benson-Manica wrote:
I have the following situation: Page A opens a window named 'foo'.
Page A then reloads itself. Is there a way for the reloaded Page A to
determine whether there is an open window named 'foo', *without*
calling window.open?


Put it another way, that's a problem of client-side state keeping; usual
approaches should apply (frames, cookies), with the popup telling it has
successfully been opened or closed, storing the information either in a
frame or in a cookie.
HTH,
Yep.
Jul 23 '05 #2
Yann-Erwan Perio <ye*@invalid.com> wrote:
Put it another way, that's a problem of client-side state keeping; usual
approaches should apply (frames, cookies), with the popup telling it has
successfully been opened or closed, storing the information either in a
frame or in a cookie.


I've been using the frame approach when it's convenient, but there are
some places where it isn't, unfortunately. The cookie idea may or may
not be an option (I'll ask in the morning) but it sounds like it may
be workable. Thanks.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #3
Christopher Benson-Manica wrote:
I have the following situation: Page A opens a window named 'foo'.
Page A then reloads itself. Is there a way for the reloaded Page A to
determine whether there is an open window named 'foo', *without*
calling window.open?


Not with javascript.

Any reference your page has to an opened window is lost as soon as you
navigate away from the page - even to re-load it.

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).

Given the unreliability of any potential solution, the exercise is
futile. Try the following code in various browsers:
<script type="text/javascript">

function openFoo(){
Foo = window.open('', 'Foo', 'width=300,height=150')
Foo.document.write('<h1>Hi, I\'m Foo</h1>');
Foo.document.close();
}

function checkFoo() {
var msg = document.getElementById('msg')
msg.innerHTML = 'Can\'t find \'Foo\'';
if ( 'undefined' != typeof Foo ) {
msg.innerHTML = 'Found ' + typeof Foo + ' Foo';
if ( 'object' == typeof Foo && window.constructor ) {
msg.innerHTML += '<br>And it\'s a ' + Foo.constructor;
}
}
}

function closeFoo() {
if ( window.Foo ) {
window.Foo.close();
}
}

</script>
<div style="padding-top: 100px;">
<input type="button" value="Open Foo" onclick="
openFoo(); setTimeout('checkFoo()', 10);
">
<input type="button" value="Check for Foo" onclick="checkFoo();">
<input type="button" value="Close Foo" onclick="
closeFoo(); setTimeout('checkFoo()', 10);
">
</div>
<p id="msg"></p>


--
Rob
Jul 23 '05 #4
RobG <rg***@iinet.net.auau> wrote:
Not with javascript.
That's what I figured, unfortunately.
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).


It might be good enough for my purposes, however; I only need a
reasonable guess that the window is still open, not an absolute
assurance.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #5
ASM
Christopher Benson-Manica wrote:

It might be good enough for my purposes, however; I only need a
reasonable guess that the window is still open, not an absolute
assurance.


the only way I see
is to have a routine (loop) in popup sending regulary
to it's opener a variable to true (known by the page in main window)

Anyway : what that for ?
after refresh, the opener will not more be abble to acces to the popup
i.e. to give it back focus

or more popup functions waiting opener's variables telling him
do that or this ?

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #6
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.
Jul 23 '05 #7
ASM
Yann-Erwan Perio wrote:
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).
even with a setTimeout ?
--- winopen.html ---
suppose winopen.html is the page in popup ?
<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 "";
}
}
this below wouldn't be in main page (opener)
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>
---


other way could be to work with 3 windows
whom one could be the common memory
http://perso.wanadoo.fr/stephane.mor...popup_oui_non/

bot main page in a frame of main window is the best
(main window get common memory)

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #8
ASM wrote:

Salut Stéphane,
(but not Opera, because
they've always refused to trigger onunload events when the page is
closing).
even with a setTimeout ?
Even with a setTimeout:-) This is a design decision of Opera, no
onunload event is triggered when the window is closed.

Opera should be praised for the attention they put in trying to protect
the end-user, but I sometimes find they're overly protective,
restricting/copying features where they shouldn't. In the case of the
onunload, IIRC, they argued this was done to prevent "good bye" alert
boxes (while a website being that annoying would certainly not retain
its visitors, and as a result would remove the functionality).
suppose winopen.html is the page in popup ?
Nope, this is the contrary:-)
other way could be to work with 3 windows
whom one could be the common memory


Technically yes, but opening a third window would be a pain to the user
(who'd try to close it at once).
Regards,
Yep.
Jul 23 '05 #9
ASM <st*********************@wanadoo.fr> wrote:
Anyway : what that for ?
after refresh, the opener will not more be abble to acces to the popup
i.e. to give it back focus


My understanding is that calling window.open will return a handle to
the named window if it is already open...

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Cliff Wells | last post by:
Hi, I'm writing an application that needs to know if an Internet connection is available. Basically, I want to have something similar to what a lot of email clients have, where the app can work...
8
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window...
2
by: Rob Mandeville | last post by:
I need to open a file, and determine if: 1: I actually opened it 2: I couldn't open it because it doesn't exist, or 3: I couldn't open it for other reasons, such as file permissions. I'm...
1
by: CES | last post by:
I'm looking for a JavaScript/.net replacement for Netscape's window.outerWidth that will work in IE and was wondering is their a way of determining if the search/history/favorites/etc. sidebar is...
4
by: petermichaux | last post by:
Hi, I'm hoping for a reason I'm wrong or an alternate solution... I'd like to be able to dynamically include some javascript files. This is like scriptaculous.js library but their solution is...
19
by: catmansa | last post by:
Is there anyway to determine the present pixel height & width size of a open browser window? :)
4
by: Nathan Sokalski | last post by:
When determining whether a String can be converted to a DateTime, you can use the IsDate() method. However, I would also like to know whether the string is a date, a time, or both a date and a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.