473,695 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 24704
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.htm l" target="myNewWi ndow1">open new window 1</a><br>
<a href="test3.htm l" target="myNewWi ndow2">open new window 2</a><br>
<a href="test3.htm l" target="myNewWi ndow3">open new window 3</a><br>
<hr>
<form>
Click <input type="button" value="here" onClick="makeSu mmaryWindow()"> to
open summarywindow.
</form>
<hr>
<script type="text/javascript">
var summaryWindow;
function makeSummaryWind ow(){
summaryWindow = window.open("", "mySummaryWindo w");
summaryWindow.d ocument.open();
summaryWindow.d ocument.write(" summary");
summaryWindow.d ocument.close() ;
}

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

</body>
</html>

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

<html>
<body>
I am childwindow
<br>
<script type="text/javascript">
var myOpener = opener;
var theSummaryWindo wHandle = opener.getSumma ryWindowHandle( );
alert("myOpener ="+myOpener) ;
alert("theSumma ryWindowHandle= "+theSummaryWin dowHandle);
</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.co m (NeverLift) wrote in message news:<98******* *************** ****@posting.go ogle.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.ht ml</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,htmlFi le)
{
var theData, newWindow, URLstring, pass;

theData = "?none=none ";
URLstring = htmlFile + theData;
pass = "statusbar,menu bar,resizable,t oolbar," +
"height=300,wid th=500,location ";
winList[name].window = window.open(URL string,name,pas s);

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.htm l");
}
else if (maxCheck++ < 30)
{
setTimeout("che ckForOpen()",10 00);
}
else
{
alert("setTmeou t for checkForOpen has ended");
}

}
</script>

</HEAD>

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

<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='opene r.resetVar("win First");'>
<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='opene r.resetVar("win Second");'>
<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
3344
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? The following page2.asp won't output the value entered in page1.asp. However, if we do <form action="page2.asp" method="get" target="_blank">, then it will open a new window for the request page, instead of using the same window as page1.asp....
10
11228
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="#" onClick="window.open('/cgi-bin/displayimage.cgi?/store/demo/image.jpg&YOUR+PRODUCT%27<b>S+NAME+GOES', 'fullimage', 'WIDTH=420,HEIGHT=405,status=0')"> The original window should not reload, but is, and I have tested it with both version 4.72 and 7.02, and they both do it. IE does not do it....
29
5012
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 window properly but does not pass the parameter. (this is part of a coldfusion template) <a href="##"
0
1310
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
1978
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 isn't very useful if you want to fetch information from an existing document in the window. One solution I came up with was quite simple; open the "new" window, giving you a reference to the object, then use window.history.back() to
1
1938
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
1241
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
2642
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 download script, so customers on the website can download MP3s to their harddrive (rather than merely listen to it in their browsers):
3
3728
by: Leo Lee | last post by:
I need a window's handle to be passed to external c++. Thanks in advance
0
8585
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
9132
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...
1
8864
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6506
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
4351
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
4592
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3024
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2288
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1986
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.