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