473,763 Members | 3,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)cybers pace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #1
9 3463
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.co m> 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)cybers pace.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,heig ht=150')
Foo.document.wr ite('<h1>Hi, I\'m Foo</h1>');
Foo.document.cl ose();
}

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

function closeFoo() {
if ( window.Foo ) {
window.Foo.clos e();
}
}

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


--
Rob
Jul 23 '05 #4
RobG <rg***@iinet.ne t.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)cybers pace.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.leng th+1;
if ((!start)&&
(name != document.cookie .substring(0,na me.length))){
return null;
}
if (start == -1) return null;
var end = document.cookie .indexOf(";",le n);
if (end == -1) end = document.cookie .length;
return unescape(docume nt.cookie.subst ring(len,end));
}else{
return "";
}
}

function op(a){
window.open(a.h ref, a.target);
return false;
}
</script>

<a href="wintest.h tml" 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,sec ure) {
if(typeof document.cookie == "string"){
document.cookie = name + "=" +escape(value) +
( (expires) ? ";expires=" + expires.toGMTSt ring() : "") +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
( (secure) ? ";secure" : "");
}
}

window.onload=f unction(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.leng th+1;
if ((!start)&&
(name != document.cookie .substring(0,na me.length))){
return null;
}
if (start == -1) return null;
var end = document.cookie .indexOf(";",le n);
if (end == -1) end = document.cookie .length;
return unescape(docume nt.cookie.subst ring(len,end));
}else{
return "";
}
}
this below wouldn't be in main page (opener)
function op(a){
window.open(a.h ref, a.target);
return false;
}
</script>

<a href="wintest.h tml" 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,sec ure) {
if(typeof document.cookie == "string"){
document.cookie = name + "=" +escape(value) +
( (expires) ? ";expires=" + expires.toGMTSt ring() : "") +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
( (secure) ? ";secure" : "");
}
}

window.onload=f unction(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************ *********@wanad oo.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)cybers pace.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
3665
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 either in "online" or "offline" mode (it keeps a cache of downloaded info, so it can work without a connection if needed). The basic problem is this: it downloads info (RSS feeds) from a variety of sources. Any one (or more) of these could...
8
2534
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 would be returned an instance of the class. The actual application I'm interested in writing would either have simple type attributes (int, string, etc.), or attributes using types already defined in a c-extension, although I'd prefer not to...
2
1951
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 using ifstream for this, and I can tell if it opened or not. But if it doesn't open, how do I tell whether the file exists or not? Here's what I have so far:
1
964
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 open ??? Any other suggestion on how to find the total with of the IE window would be appreciated. Thanks CES
4
2161
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 broken in Firefox 1.5.0.1 on OS X. What happens with the Scriptaculous library is this In the html document the author only has to include one line
19
2134
by: catmansa | last post by:
Is there anyway to determine the present pixel height & width size of a open browser window? :)
4
2119
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 time. Is there any simple way to do this without using manual pattern matching? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10145
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9822
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.