windows object identity

  • Thread starter mikharakiri_nospaum
  • Start date
M

mikharakiri_nospaum

Is there a way to tell one window from another? A quick look into wndow
object properties revealed nothing obvious. I want to keep track of
window object identity in a hidden input widget, so that whenever user
clones the window, I'll be able identify this and provide an extra
session.
 
T

Thomas 'PointedEars' Lahn

Is there a way to tell one window from another?

Sure. If window1 == window2 yields `false', the Window objects referred to
are different, otherwise both references point to the same Window object.


PointedEars
 
M

mikharakiri_nospaum

Thomas said:
Sure. If window1 == window2 yields `false', the Window objects referred to
are different, otherwise both references point to the same Window object.

Yes, but the scope is outside of Java Script environment. I want to
save window.id or its equivalent as a text string in a hidden form
widget that can be passed as parameter to servlet/JSP processor. Within
the javascript on page, I prefer not to have any knowledge about the
other browser windows.
 
R

Randy Webb

Thomas 'PointedEars' Lahn said the following on 4/21/2006 10:51 PM:
Sure. If window1 == window2 yields `false', the Window objects referred to
are different, otherwise both references point to the same Window object.

You really should learn to read, and comprehend, English before replying
to a lot of the posts you reply to. Had you continued reading, and
comprehended, the context you would have been able to give a better -
more informed - response.

The answer to the question is no. And you are, yet again, showing your
immature pedantic behavior.

Now, go ahead, use your ad hominem defense.
 
A

ASM

(e-mail address removed) a écrit :
Yes, but the scope is outside of Java Script environment. I want to
save window.id or its equivalent as a text string in a hidden form
widget that can be passed as parameter to servlet/JSP processor. Within
the javascript on page, I prefer not to have any knowledge about the
other browser windows.

windows names are only known by the file loaded (or at best by the window)

I think that to refer to a (precedent) window.name in a new file loaded
would'nt be abble to work.

Anyway I don't understand why you need to know in witch windows files
are displayed.
Isn't problem of the browser or its user ?
 
T

Touffy

Yes, but the scope is outside of Java Script environment. I want to
save window.id or its equivalent as a text string in a hidden form
widget that can be passed as parameter to servlet/JSP processor. Within
the javascript on page, I prefer not to have any knowledge about the
other browser windows.

I don't really understand what you intend to do with those IDs.

First, if you want all windows with your site loaded into them to
communicate with each other directly :

Are your extra windows opened by JavaScript (window.open) or do you
want to track any window opened ?

For exemple, if the user manually opens two tabs (or windows) in his
browser and connects to your website on both, a script in one tab will
*never* be able to access the other directly. They could communicate
via the server, or by sharing cookies.

If you care only about window.open'ed windows, then the opener has a
reference to the popup (the value returned by window.open()) and the
popup can use window.opener to access it's opener.

But that has nothing to do with IDs.

Either way you could give a unique ID to each window (that's the
session ID you're already using anyway, so no problem here, just assign
an "id" property to the window if you want to formalize that), but of
course this id cannot be found by getElementById().

If the windows can access each other, then they can read each other's
id property (I still can't begin to guess why you'd want them to do
that). If not, too bad.
 
M

mikharakiri_nospaum

Touffy said:
Are your extra windows opened by JavaScript (window.open) or do you
want to track any window opened ?

Cloning new browser window is as simple as "Ctrl-New Window". The end
user may continue his session from a new window as well as the old one.
For exemple, if the user manually opens two tabs (or windows) in his
browser and connects to your website on both, a script in one tab will
*never* be able to access the other directly. They could communicate
via the server, or by sharing cookies.

I dont want one window to be aware of the other one.. All I want from
the script is to tell some surrogate value of the window identity. This
could be just raw address.

I'm kind of perplexed. Any OO programming language can output the
reference/pointer to the object. Not in JS?
Either way you could give a unique ID to each window (that's the
session ID you're already using anyway, so no problem here, just assign
an "id" property to the window if you want to formalize that), but of
course this id cannot be found by getElementById().

Therefore, you refer me to the session variable in JSP (which BTW I
don't use)? How does JSP/Servlet session behaves when I clone the
window? (If they are different then it solves my problem)
 
M

mikharakiri_nospaum

How does JSP/Servlet session behaves when I clone the
window? (If they are different then it solves my problem)

Just tested: The session object for the cloned browser window is the
same:-(
 
T

Thomas 'PointedEars' Lahn

I dont want one window to be aware of the other one.. All I want from
the script is to tell some surrogate value of the window identity. This
could be just raw address.

Each window must have a different name, so you could use the `name' property
of Window objects.
I'm kind of perplexed. Any OO programming language can output the
reference/pointer to the object. Not in JS?

I have already said that you can compare Window object references against
each other, have I not?

But if the user opens the window, there is no reference/pointer to an object
in JS, unless you access the Windows (or whatever) API. Browser windows
are _not_ part of the programming language (they have been, but that was
in the JS-on-NN/IE-only times) but of the Application Object Model the
browser provides. It is your fault not recognizing that, not JS's.


PointedEars
 
M

mikharakiri_nospaum

Thomas said:
Each window must have a different name, so you could use the `name' property
of Window objects.

How? The script

<script>
alert(window.name)
</script>

outputs blank value

If I clone the window, the output doest change.
But if the user opens the window, there is no reference/pointer to an object
in JS, unless you access the Windows (or whatever) API.

OK, failing that, is there other programmtic method to distinguish
between browser windows?
 
V

VK

OK, failing that, is there other programmtic method to distinguish
between browser windows?

You cannot distinguish between windows from windows themselves. This
possibility was locked from the beginning and it was even more narrowed
over the last decade. The reason is security and privacy reasons, not
technical issues.

In the cloned window script will be initialized over again (current
state is not cloned). Using this you may mark each window onload:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function mark() {
self['$mark'] = (new Date()).getTime();
}
</script>
</head>

<body onLoad="mark()">
<form method="post" action="">
<input type="button" name="b001" value="Button"
onClick="alert(self['$mark'])">
</form>
</body>
</html>

as you see any cloned window has its own $mark value.

But as the current script state is not cloned, the subject of your
concerns is really escaping me. On Ctrl+N user doesn't get a copy of
the current session: it gets a "clear copy" of the page as it was on
the first load.
 
M

mikharakiri_nospaum

VK said:
OK, failing that, is there other programmtic method to distinguish
between browser windows?
In the cloned window script will be initialized over again (current
state is not cloned). Using this you may mark each window onload:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function mark() {
self['$mark'] = (new Date()).getTime();
}
</script>
</head>

<body onLoad="mark()">
<form method="post" action="">
<input type="button" name="b001" value="Button"
onClick="alert(self['$mark'])">
</form>
</body>
</html>

as you see any cloned window has its own $mark value.

Unfortunately the timestamp keeps changing every time the page is
reloaded, so it doesn't satisfy the other requrement that windows
identity stays the same during the session in the same browser window.
But as the current script state is not cloned, the subject of your
concerns is really escaping me. On Ctrl+N user doesn't get a copy of
the current session: it gets a "clear copy" of the page as it was on
the first load.

OK, that is minor terminology snag. Ctrl+N copies over the application
state of the browser window minus Java Script state (which isn't the
issue for my application anyway).
 
V

VK

Unfortunately the timestamp keeps changing every time the page is
reloaded, so it doesn't satisfy the other requrement that windows
identity stays the same during the session in the same browser window.

You cannot bulletproof track down separate windows. You may identify
*clients* by cookies (if enabled). This is one of "disconveniences" of
the Web same as you cannot search on local drives or write from the
browser right to the local file (I'm talking about the default
circumstances). Hugely disconvenient :) - but WONTFIX.

If your solution is absolutely dependant on proper windows tracking, it
simply means that it is not a Web solution. You either have to choose
an appropriate Web solution, or write a web-enabled executable to
destribute to your clients. As simple as that.

Ctrl+N copies over the application
state of the browser window minus Java Script state (which isn't the
issue for my application anyway).

On each Ctrl+N your script will call onload handler in the new window.
You can mark the new window, ajax some data to the server, adjust
cloned form field values - whatever. So I'm still missing the technical
problem.

No, you cannot have 100% guarantee that each new window case will be
tracked and properly reported. If it's a must, then see the first part
of this post.
 
B

bgulian

Is there a way to tell one window from another? A quick look into wndow
object properties revealed nothing obvious. I want to keep track of
window object identity in a hidden input widget, so that whenever user
clones the window, I'll be able identify this and provide an extra
session.


As you've probably deduced by now, within the javascript environment,
there is no way to identify browser windows. What I and my colleagues
ended up doing was asking an ActiveX control for the window handle (IE
only of course but unfortunately that is the requirement for this
software). Then we stored the handle in a session cookie. It's
incredibly complex but we can now do many things that ASP sessions did
not let us do.

A truly limitied answer and probably not helpful at all but a nice
break from the guru fight.

Bob Gulian
 
T

Thomas 'PointedEars' Lahn

As you've probably deduced by now, within the javascript environment,
there is no way to identify browser windows.

Yes, there is. As I said, provided that we assume that the `name' property
of new Windows is empty or does simply not match "our" format, it is
possible to set that property with string format containing a unique value
(new Date().getTime() comes to mind), and thereby identify the browser
window (at least the Window object we are working with; that may be a tab,
too).
A truly limitied answer and probably not helpful at all but a nice
break from the guru fight.

The ability to draw meaning from posted text can be an important advantage
around here. So much for "guru fight".


PointedEars
 
R

Randy Webb

Thomas 'PointedEars' Lahn said the following on 4/25/2006 11:43 AM:
Yes, there is.

No there isn't.
As I said, provided that we assume that the `name' property of new Windows

And if the name property isn't set then it means nothing to you and
breaks your "scheme".
is empty or does simply not match "our" format, it is
possible to set that property with string format containing
a unique value (new Date().getTime() comes to mind), and
thereby identify the browser window (at least the Window
object we are working with; that may be a tab, too).

"it is possible"? Is that your way of defending your ludicrous idea?
When someone says it doesn't work, you can reply that you said "It is
possible"?

But guess what Mr PointedEars? If the page is opened in a new *tab* then
you have no new *window* to deal with. Do you lack the ability to
recognize the difference? Obviously not.
The ability to draw meaning from posted text can be an important advantage
around here. So much for "guru fight".

Yes, and your ability to draw the *proper* meaning from the English
language have been proven to be faulty at best so what you "draw
meaning" from doesn't mean a whole lot.
 
B

bgulian

Thomas said:
Yes, there is. As I said, provided that we assume that the `name' property
of new Windows is empty or does simply not match "our" format, it is
possible to set that property with string format containing a unique value
(new Date().getTime() comes to mind), and thereby identify the browser
window (at least the Window object we are working with; that may be a tab,
too).

And if the user clones the window as the originator of this thread
postulated, will that name property still contain our identifier? No.
It would probably help the cause of enlightenment if you remembered the
original question instead of inventing your own.


Bob Gulian
 
T

Thomas 'PointedEars' Lahn

And if the user clones the window as the originator of this thread
postulated, will that name property still contain our identifier? No.

Of course not. That is /exactly/ what makes "cloned" windows _different_
from "original" windows. Which is /exactly/ what the OP wants.
It would probably help the cause of enlightenment if you remembered the
original question instead of inventing your own.

Pot, kettle, black. The OP wants to recognize different browser windows,
and create a new server-side session for each new window:

,-<|
| I dont want one window to be aware of the other one.. All I want from
| the script is to tell some surrogate value of the window identity. This
| could be just raw address.
| [...]

,-<|
| > Therefore, you refer me to the session variable in JSP (which BTW I
| > don't use)? How does JSP/Servlet session behaves when I clone the
| > window? (If they are different then it solves my problem)
|
| Just tested: The session object for the cloned browser window is the
| same:-(

The client-side part of it is really quite simple:

<head>
...
<script type="text/javascript">
// you must obey the rules for window names, set by DOM Level 0, here
if (typeof window.name != "undefined")
{
if (!/^_myWindow/.test(window.name))
{
window.name = "_mywindow" + new Date().getUTCTime();
}
}
</script>
...
</head>

This will assign the Window object a new unique name when the corresponding
window is opened (or "cloned"), and will keep that value if it is
refreshed, or navigation happens in it. And the best part of it is that it
works with tabs, too.[1]


Score adjusted

PointedEars
___________
[1] tested in Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.2)
Gecko/Debian-1.5.dfsg+1.5.0.2-3 Firefox/1.5.0.2
 
T

Thomas 'PointedEars' Lahn

And if the user clones the window as the originator of this thread
postulated, will that name property still contain our identifier? No.

Of course not. That is /exactly/ what makes "cloned" windows _different_
from "original" windows. Which is /exactly/ what the OP wants.
It would probably help the cause of enlightenment if you remembered the
original question instead of inventing your own.

Pot, kettle, black. The OP wants to recognize different browser windows,
and create a new server-side session for each new window:

,-<|
| I dont want one window to be aware of the other one.. All I want from
| the script is to tell some surrogate value of the window identity. This
| could be just raw address.
| [...]

,-<|
| > Therefore, you refer me to the session variable in JSP (which BTW I
| > don't use)? How does JSP/Servlet session behaves when I clone the
| > window? (If they are different then it solves my problem)
|
| Just tested: The session object for the cloned browser window is the
| same:-(

The client-side part of it is really quite simple:

<head>
...
<script type="text/javascript">
// you must obey the rules for window names, set by DOM Level 0, here
if (typeof window.name != "undefined")
{
if (!/^_myWindow/.test(window.name))
{
window.name = "_mywindow" + new Date().getTime();
}
}
</script>
...
</head>

This will assign the Window object a new unique name when the corresponding
window is opened (or "cloned"), and will keep that value if it is
refreshed, or navigation happens in it. And the best part of it is that it
works with tabs, too.[1]


Score adjusted

PointedEars
___________
[1] tested in Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.2)
Gecko/Debian-1.5.dfsg+1.5.0.2-3 Firefox/1.5.0.2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top