windows object identity

  • Thread starter mikharakiri_nospaum
  • Start date
B

bgulian

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.

Upon furthur investigation it looks like I shot off my mouth too soon.
Thomas is correct. The window.name retains the value you give it upon
refresh. It is a perfectly reasonable way to uniquely identify windows
and be able to read that identification at any time.

I apologize for my comment. I let the urge to correct you for the way
you say things prevail nstead of listening to what you were actually
saying.

Bob Gulian
 
M

mikharakiri_nospaum

...
<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]

Nice try. Doesn't work. JSP page code:

<html>
<head>
<title>Test Window</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<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>

<body>
<form method="post" action="">
<input type="button" name="b001" value="Button"
onClick="alert(window.name);submit()">
</form>
</body>
Session Id is <%= session.getId()%>

</html>

The name of the window keeps changing whenever I press the button.

Let me again state the requirements:
1. If I navigate pages in the same browser window, the session (aka
"window identity") stays the same. Ditto for navidating with browser
"go back/forward one page".

2. If window is cloned, the identity should change. Ditto for browser
tabs.

BTW, CTRL-N doesn't clone window in Mozilla (it invokes new windoe with
the default page). Am I missing some setting?
 
M

mikharakiri_nospaum

Let me again state the requirements:
1. If I navigate pages in the same browser window, the session (aka
"window identity") stays the same. Ditto for navidating with browser
"go back/forward one page".

2. If window is cloned, the identity should change. Ditto for browser
tabs.

The last sentence indicates that I focus on session management, not
window identity. What is the session definition? Session is some linear
sequence of pages that user can navigate back in forth in time. Any
time a web page gets cloned into a new tab or browser window, a new
session is spawned. This is a new session because the old one is still
present and there is no way to merge the new session into the old one.

Now the question: how do I manage the session on client side?
Apparently, without client support server side has no way to manage
sessions. (This strikes me as an extremely odd idea that JSP/Servlet
session concept -- which is about 10 years old concept -- is something
defferent from what I just described).
 
T

Thomas 'PointedEars' Lahn

<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]

Nice try. Doesn't work.

Yes, it does. ("Does not work" is a useless error description. [psf 4.11])
JSP page code:
[...]
<form method="post" action="">
<input type="button" name="b001" value="Button"
onClick="alert(window.name);submit()">

It should be `this.form.submit();', if that.
</form>
[...]
The name of the window keeps changing whenever I press the button.

Confirmed. The reason was that I had disregarded letter case (and did not
look for a case-insensitive match). Therefore, the Regular Expression did
not match.

However, the name is not changed with the (in contrast to your code) Valid
markup[1]

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Test Window</title>

<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
if (typeof window.name != "undefined")
{
if (!/^_myWindow/.test(window.name))
{
window.name = "_myWindow" + new Date().getTime();
}
}
</script>
</head>

<body>
<form action="" method="post">
<input type="submit" name="b001" value="Submit">
<script type="text/javascript">
document.write(window.name);
</script>
</form>

Session Id is ...
</body>
Let me again state the requirements:
1. If I navigate pages in the same browser window, the session (aka
"window identity") stays the same. Ditto for navidating with browser
"go back/forward one page".

2. If window is cloned, the identity should change. Ditto for browser
tabs.

If I "Duplicate" the window in IE6 SP1 on Win2k SP4 (with .NET 1.1
support) with C-N, or the window or tab with Tabbrowser Extensions in
Firefox/1.5.0.2, in Opera/9 Beta, and in Konqueror/3.52, the window
name definitely changes.[1] With the above correction, it does not
if I refreshed the document or navigated in that window afterwards,
including submit to the same document resource.

However, if your "cloning" for some reason "clones" the window name
as well, I am afraid you are out of luck.
BTW, CTRL-N doesn't clone window in Mozilla (it invokes new windoe with
the default page). Am I missing some setting?

Mozilla SeaMonkey Suite[1] has a setting to define what should happen if
a new window/tab is opened by the user (with C-N or otherwise); you would
have to set "Edit/Preferences/Navigator/Display on New Window|Tab" to "Last
page visited". Mozilla Firefox apparently misses either that preference or
the corresponding UI, and simply does not clone by default. Neither do
Opera or Konqueror then.

Please _always_ provide attribution of quoted material.


PointedEars
___________
[1] <URL:http://validator.w3.org/>
[2] (Unforged) UA header strings:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)

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

Opera/9.00 (X11; Linux i686; U; en)

Mozilla/5.0 (compatible; Konqueror/3.5; Linux
2.6.15.6-20060314.201202+0100; X11; i686; de, en_US)
KHTML/3.5.2 (like Gecko) (Debian package 4:3.5.2-2+b1)
 
V

VK

What is the session definition? Session is some linear
sequence of pages that user can navigate back in forth in time. Any
time a web page gets cloned into a new tab or browser window, a new
session is spawned. This is a new session because the old one is still
present and there is no way to merge the new session into the old one.

That is the most odd session definition I've ever seen so far (and I
saw a lot of odd things). Session (from the server point of view) is
the moment of the first request for a transaction and till the moment
of the final request finishing the transaction. If it's a multi-step
transaction, on the first request your create an unique session ID and
a session record/file to keep the intermediate submission data. On each
new request you check these data and if the session is not expired and
credentials (if any) are in order you serve the next step page. You
cannot control how did the current request came to you: from the
original browser window, or user cloned it in 25 copies and submitting
from from each of them, or refreshing the window, or she reverse
engineered your form and using XMLHttpRequest with timed loop. These
are just very tops of things a "curious" user may do. If you are really
so concerned about transactions stability, then the matter is way above
of JavaScript domain and any "window identification" cheat-chat. You
need first to program the decisions server-side:
1) how long the session is kept before marked expired.
2) if transaction record stopped on step 5 and next request came for
step 2, are you serving step 2 with roll-back data or will you say
"sorry Joe, no way"
3)
4)
5)
....
33)
....
Some good book about transaction server could be really helpful here.
 
M

mikharakiri_nospaum

VK said:
That is the most odd session definition I've ever seen so far (and I
saw a lot of odd things). Session (from the server point of view) is
the moment of the first request for a transaction and till the moment
of the final request finishing the transaction. If it's a multi-step
transaction, on the first request your create an unique session ID and
a session record/file to keep the intermediate submission data. On each
new request you check these data and if the session is not expired and
credentials (if any) are in order you serve the next step page. You
cannot control how did the current request came to you: from the
original browser window, or user cloned it in 25 copies and submitting
from from each of them, or refreshing the window, or she reverse
engineered your form and using XMLHttpRequest with timed loop. These
are just very tops of things a "curious" user may do. If you are really
so concerned about transactions stability, then the matter is way above
of JavaScript domain and any "window identification" cheat-chat. You
need first to program the decisions server-side:
1) how long the session is kept before marked expired.
2) if transaction record stopped on step 5 and next request came for
step 2, are you serving step 2 with roll-back data or will you say
"sorry Joe, no way"
3)
4)
5)
...
33)
...
Some good book about transaction server could be really helpful here.

Crossposting to comp.java.lang.programmer where server side discussion
is on the way...

To clarify, the application is a SQL workbench. A user enters SQL
statement in a form, submits the request, and gets nicely formatted
result in the next page. He enters new query there, and so on.

Therefore, the session that I want to maintain on server is JDBC
connection. Now among all the obvious things that I do on middle tier
-- connection pooling, connection timeouts -- I have to define client
session too. Otherwise, every new SQL query would create a new JDBC
connection.

There is no transaction spanning multiple pages. Each query is a
transaction. A SQL command history is the browser history. A user can
navigate with the browser back button to the commands he entered early.
This is why the session is the sequence of pages.
 
M

mikharakiri_nospaum

If I "Duplicate" the window in IE6 SP1 on Win2k SP4 (with .NET 1.1
support) with C-N, or the window or tab with Tabbrowser Extensions in
Firefox/1.5.0.2, in Opera/9 Beta, and in Konqueror/3.52, the window
name definitely changes.[1] With the above correction, it does not
if I refreshed the document or navigated in that window afterwards,
including submit to the same document resource.

As I'm duplicating the window with Ctrl-N, your solution works for me.
Thanks.
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top