473,245 Members | 1,795 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,245 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 24630
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.