472,127 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

problems detecting a window



Hi,

My question is this : how do I detect from
another window which didn't create a new window whether
it exists ? For example, is there a window-id's container
of some sort that hangs around that I can interrogate ?

I would like to find a better way of doing the following.
I have a window (call it Win) that creates a new window (call it Win2)
using window.open().
It detects if the window already exists and brings it to the front if it
does (else it just creates it). That works fine within the creator
window Win.

The problem occurs when I reload window Win and hit the create-window
button. The Win2 window is reset and reloads
from scratch. I want it to just be brought to the top.

(Context :In my work what I do is have the Order button bring up an
order form from an item page. Then going to another item page hitting
order should not reload the order form since then all the previous item
orders are thrown away - I just raise it to the top if its hidden.)
ok thanks for any help.
here's the code :

<html>
<head>
<script language="javascript">

var popupwin;
function NewWindow(mypage,myname)
{

if ( popupwin==null || popupwin.closed ) // the window doesn't exist
or is closed so create it and bring it to the top
{
popupwin=window.open(mypage,myname,""); popupwin.focus();
}

else
{
popupwin.focus(); // the window exists so just bring it to the top
}
}
</script>

</head>
<body>
<button type="button"
onClick="NewWindow('http://www.google.com','orderform')" >Order
</button>
</body></html>

-Dom
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
2 4825
Give the following code a try, it worked for me on IE6 and NS7.

-Wagner

<html>
<head>
<script language="javascript">
var popupwin;
function NewWindow(mypage,myname)
{
if ( !popupwin || popupwin.closed ){
popupwin=window.open("",myname,"");
try{
popupwin.location.href; // throws exception if after reload
popupwin.location = mypage;
}catch(e){};
}
popupwin.focus();
}
</script>
</head>
<body>
<button type="button"
onClick="NewWindow('http://www.google.com','orderform')" >Order
</button>
</body></html>

Dom Nicholas <no********@thanks.com> wrote in message news:<3f*********************@news.frii.net>...
Hi,

My question is this : how do I detect from
another window which didn't create a new window whether
it exists ? For example, is there a window-id's container
of some sort that hangs around that I can interrogate ?

I would like to find a better way of doing the following.
I have a window (call it Win) that creates a new window (call it Win2)
using window.open().
It detects if the window already exists and brings it to the front if it
does (else it just creates it). That works fine within the creator
window Win.

The problem occurs when I reload window Win and hit the create-window
button. The Win2 window is reset and reloads
from scratch. I want it to just be brought to the top.

(Context :In my work what I do is have the Order button bring up an
order form from an item page. Then going to another item page hitting
order should not reload the order form since then all the previous item
orders are thrown away - I just raise it to the top if its hidden.)
ok thanks for any help.
here's the code :

<html>
<head>
<script language="javascript">

var popupwin;
function NewWindow(mypage,myname)
{

if ( popupwin==null || popupwin.closed ) // the window doesn't exist
or is closed so create it and bring it to the top
{
popupwin=window.open(mypage,myname,""); popupwin.focus();
}

else
{
popupwin.focus(); // the window exists so just bring it to the top
}
}
</script>

</head>
<body>
<button type="button"
onClick="NewWindow('http://www.google.com','orderform')" >Order
</button>
</body></html>

-Dom
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #2
DU
Dom Nicholas wrote:

Hi,

My question is this : how do I detect from
another window which didn't create a new window whether
it exists ?
Not possible in a default security environment. Just imagine if it was
possible: it would lead to abuse on the web.
Not recommendable either. You might be reloading an entirely different
opener window: why should its previously related sub-window, secondary
window be the same as the previous opener?

For example, is there a window-id's container of some sort that hangs around that I can interrogate ?

I would like to find a better way of doing the following.
Now, this is what is most likely the proper way to present your problem.
You need to explain your website, webpage context; what you really want
to do, what your webpage is about, webpage requirements, etc...
I have a window (call it Win) that creates a new window (call it Win2)
using window.open().
It detects if the window already exists and brings it to the front if it
does (else it just creates it). That works fine within the creator
window Win.

The problem occurs when I reload window Win and hit the create-window
button. The Win2 window is reset and reloads
from scratch. I want it to just be brought to the top.

The pointer stored by the opener, regarding the opener to the child
window is lost when the opener is entirely reloaded.
What you're explaining is one limitation and one constraint (among many
others) regarding secondary windows. That's just one reason why
requested popup windows is usually (I didn't say always) not recommendable.
(Context :In my work what I do is have the Order button bring up an
order form from an item page. Then going to another item page hitting
order should not reload the order form since then all the previous item
orders are thrown away - I just raise it to the top if its hidden.)
ok thanks for any help.
here's the code :

<html>
<head>
<script language="javascript">

var popupwin;
function NewWindow(mypage,myname)
{

if ( popupwin==null || popupwin.closed ) // the window doesn't exist
or is closed so create it and bring it to the top
{
popupwin=window.open(mypage,myname,""); popupwin.focus();
This popupwin.focus() call in that previous line is illogical, at least
redundant. If the requested popup window is not existing or is closed,
then create it and give it focus. There is no need to bring it on top
since the instruction creates it.
}

else
{
popupwin.focus(); // the window exists so just bring it to the top
}
}
</script>

</head>
<body>
<button type="button"
onClick="NewWindow('http://www.google.com','orderform')" >Order
</button>
</body></html>

-Dom
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by bill ramsay | last post: by
1 post views Thread by Erik Bethke | last post: by
10 posts views Thread by Frances Del Rio | last post: by
7 posts views Thread by Aarti | last post: by
reply views Thread by leo001 | last post: by

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.