473,416 Members | 1,564 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,416 software developers and data experts.

Getting an open window's handle from its name

But, if it's not open, I don't want to open it . . . using
window.open will open it if it doesn't exist, even if the url in that
open is null (the window is then empty -- but it's open).

The situation is: A main window opens child windows one at a time as
the user requests, each with its own name. The user may click in any
child window or the main window to open a summary window, which has a
name all windows know. I want to get that summary window's handle in
any child window, no matter which window first opened it, so the child
window can run a script in the summary to update its display, should
the user have performed a selection in that child window -- but I do
not want to open it if the user hasn't explicitly done so yet. (All
of this is client-side. The user selections are being accumulated in
the cookie. The 2,000 byte limit is not of concern.)

I know I can have the summary self-update if it's open and the user
merely shifts the focus to it. But it might be visible, even if it's
not the focus, and I'd like to keep it up-to-date on the fly.

I hope that's clear. Feel free to email me directly if not.

Thanks.
Jul 23 '05 #1
3 24648
NeverLift wrote:
But, if it's not open, I don't want to open it . . . using
window.open will open it if it doesn't exist, even if the url in that
open is null (the window is then empty -- but it's open).

The situation is: A main window opens child windows one at a time as
the user requests, each with its own name. The user may click in any
child window or the main window to open a summary window, which has a
name all windows know. I want to get that summary window's handle in
any child window, no matter which window first opened it, so the child
window can run a script in the summary to update its display, should
the user have performed a selection in that child window -- but I do
not want to open it if the user hasn't explicitly done so yet. (All
of this is client-side. The user selections are being accumulated in
the cookie. The 2,000 byte limit is not of concern.)

I know I can have the summary self-update if it's open and the user
merely shifts the focus to it. But it might be visible, even if it's
not the focus, and I'd like to keep it up-to-date on the fly.

I hope that's clear. Feel free to email me directly if not.

Thanks.


Hi,

I think the easiest way to accomplish that is by keeping the reference to
the summarywindow in the mainwindow.

every childwindow that wants a handle to your summarywindow requests that by
asking their opener.
something like this

mainwindow
-----------------------------------
<html>
<body>

<a href="test3.html" target="myNewWindow1">open new window 1</a><br>
<a href="test3.html" target="myNewWindow2">open new window 2</a><br>
<a href="test3.html" target="myNewWindow3">open new window 3</a><br>
<hr>
<form>
Click <input type="button" value="here" onClick="makeSummaryWindow()"> to
open summarywindow.
</form>
<hr>
<script type="text/javascript">
var summaryWindow;
function makeSummaryWindow(){
summaryWindow = window.open("","mySummaryWindow");
summaryWindow.document.open();
summaryWindow.document.write("summary");
summaryWindow.document.close();
}

function getSummaryWindowHandle(){
return summaryWindow;
}
</script>

</body>
</html>

-----------------------------------
And test3.html:
-----------------------------------

<html>
<body>
I am childwindow
<br>
<script type="text/javascript">
var myOpener = opener;
var theSummaryWindowHandle = opener.getSummaryWindowHandle();
alert("myOpener="+myOpener);
alert("theSummaryWindowHandle="+theSummaryWindowHa ndle);
</script>
</body>
</html>
-----------------------------------

Of course you should handle the possible non-existing summaryWindow more
nicely than I did.

Regards,
Erwin Moller
Jul 23 '05 #2
Been working on the issue, came up with something similar.

Your solution works only if the main window is the only opener of the
summary. In my case, any of the child windows may have initially asked
for the summary window . . . and even that child window is likely to be
closed as the user looks at additional child windows, each being
selected in the main window.

What I came up with is: A script in the main window that does the
opening of the summary, It might be triggered there, of course. But
the action item in a child window that is to open the summary does so by
asking its opener -- the main window -- to do so, by running that
function in the opener. It also updates the summary by running a
function in the opener, and that function can check to see if it ever
opened the summary and, if not, not doing the update to it. So, all
window handles reside in the main window, all actions for the secondary
windows (the summary window and any of its ilk) funnel through the main
window.

Now, of course, if the user closes the main window, or even goes to a
different page in it . . . no child window requests to open or update
the summary will work. hmmm.

It would be so much easier if the child windows could find the summary,
if it is open, on their own, no matter how it got opened, without having
to run to momma -- momma may be gone.

I don't think the window handle can be stuffed into the cookie, else I'd
just have each summary request check there. Or can it? My cookie use
so far is pretty basic -- chunks of text, not object references. Can a
cookie hold an object like the window handle?

{aka NeverLift}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
ga**@labdata.com (NeverLift) wrote in message news:<98**************************@posting.google. com>...
But, if it's not open, I don't want to open it . . . using
window.open will open it if it doesn't exist, even if the url in that
open is null (the window is then empty -- but it's open).


This may help...

Is your window that contains the list of open windows a popup? I
assumed that it was, but you could do the same for a frame.

You could track the status of your windows in some variables.

I used the onunload to initiate the tracking of a closed window. I
have heard that onunload was unrelaiable, but it seems tp work for me.
I put an alert at the end of resetVar and observed that resetVar was
invoked and the window closed before I hit enter. This is a good
sign because it shows can get control to do some reseting of control
states, but you are not able to block the window from exiting.

I put together three html files to show how you could track the status
of a popup window. Run main.html. You will see alert messages that
step you through the running.

I tried this on Netscape 7.1 and IE 5.2 under MacOS 10.2.6.
main.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Check before opening:main.html</TITLE>

<SCRIPT type="text/javascript">

function WinObj()
{
this.openned = false;
this.running = false;
this.window = "";
}

var winList = [ ];

winList["winFirst"] = new WinObj();
winList["winSecond"] = new WinObj();

function setVar(name)
{
winList[name].running = true;
}

function resetVar(name)
{
winList[name].openned = false;
winList[name].running = false;
}

function foo(name,htmlFile)
{
var theData, newWindow, URLstring, pass;

theData = "?none=none";
URLstring = htmlFile + theData;
pass = "statusbar,menubar,resizable,toolbar," +
"height=300,width=500,location";
winList[name].window = window.open(URLstring,name,pass);

winList[name].openned = true;
winList[name].window.focus();
}

var maxCheck = 0; // Don't run forever

function checkForOpen()
{
if (winList["winFirst"].running == true)
{
foo("winSecond","winSecond.html");
}
else if (maxCheck++ < 30)
{
setTimeout("checkForOpen()",1000);
}
else
{
alert("setTmeout for checkForOpen has ended");
}

}
</script>

</HEAD>

<BODY onload='
alert("Try to open a new window next.");
foo("winFirst","winFirst.html");
setTimeout("checkForOpen()",1000);'>

<p>Lets open two windows.</p>

</BODY>

</HTML>
winFirst.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Little html window: winFirst.html</TITLE>
</HEAD>
<BODY
onload='alert("Onload in winFirst.html, " +
"press enter within thirty seconds to open " +
"winSecond.html.");
opener.setVar("winFirst");'

onunload='opener.resetVar("winFirst");'>
<p>I am a very small html file,
but I hope to grow up someday.</p>
</HTML>
winSecond.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>

<SCRIPT type="text/javascript">
function startUp()
{
alert("From winSecond.html, " +
"focus should now go to winFirst.html " +
"after calling setVar. " +
"( Should you close the winFirst.html window. " +
"You will get another alert. " +
"To see both paths, you may press enter, " +
"then close winFirst.html then reload this one. )");

opener.setVar("winSecond");
if (opener.winList["winFirst"].openned == true)
{
opener.winList["winFirst"].window.focus();
}
else
{
alert("Problems today. Where is winFirst.html?");
}
}
</script>
<HEAD>
<TITLE>Little window too: winSecond.html</TITLE>

</HEAD>
<BODY onload='startUp();'
onunload='opener.resetVar("winSecond");'>
<p>I am too a small html file,
but I hope to grow bigger someday too.</p>
<p>Most programs seem to go that way, amigo.
Not me. I grow in complexity, but stayed small.</p>
</HTML>
Robert
Jul 23 '05 #4

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

Similar topics

1
by: Matt | last post by:
My problem is when the user click the submit button, it will launch another new window for the request page. I want to confirm we cannot use JavaScript open window functions to open a request page?...
10
by: Marshall Dudley | last post by:
When I do the following line in Netscape, the popup loads as it should, but the parent window usually, but not always, reloads as well. <a href="#"...
29
by: wayne | last post by:
Hey there... I'm having some problems passing url parameters with an open.window command. I'm not terribly familiar with java script but here is the code below. When executed it opens the...
0
by: petarm | last post by:
Hey, I am trying to implement (using C# and .NET) a routine that retrieves the window handle of another application's window by having the user click on that window. Any help? Thanks,
7
by: multicherry | last post by:
Hi, Having searched for a way to fetch a window object by name, all I came across were answers along the line of... "All you have to do is say windowObj = window.open("blah", "name");" which...
1
by: palashsingharoy | last post by:
Hi, I am trying to open one new window with some values. The following is my code .. <%@ page import="java.util.*" %> <%@ page contentType="text/html; charset=x-SJIS" %> <HTML> <HEAD>
1
by: sonasiva | last post by:
hai I am new bie for ASP I retrieved files name from a folder by using FSO problem is if i click that name link files are getting open <%
7
by: lawrence k | last post by:
I've got a music studio for a client. Their whole studio is run with Macintosh computers. Macintosh computers allow file names to have open white spaces, such as "animal hospital.mp3". I have a...
3
by: Leo Lee | last post by:
I need a window's handle to be passed to external c++. Thanks in advance
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.