By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

IE and window.name

P: n/a
Hi,

excuse me in advance for my poor english...

Do you know how solve my problem ?

I have "Page1.htm" :

<HTML><BODY>
<A href="Page2.htm" target=TOTO>window TOTO</A>
</BODY></HTML>

and I have "Page2.htm" :

<HTML><HEAD>
<SCRIPT>
function affName(i) { alert( i +" - "+ window.name ); }

affName(1);
window.name = "TITI";
affName(2);

</SCRIPT>
</HEAD><BODY onload="affName(3);">
<A href="javascript:affName(4)">window.name ?</A>
</BODY></HTML>

When I click on "fenetre TOTO" link of "Page1", a window is opened (OK)
and we have alerts :

1 - TOTO
2 - TITI
3 - TITI

All is right : "window.name" is changed from TOTO to TITI.

My problem is when I click on the "window.name ?" link of "Page2".

With NS 7, NS4+, we have :
4 - TITI ==> OK
With IE, we have :
4 - TOTO ==> Why ?

Any help would be highly appreciated.
Thank you very much in advance.

--
Yours sincerely, Thierry
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Cenekemoi wrote:
<snip>
<A href="javascript:affName(4)">window.name ?</A> <snip> With NS 7, NS4+, we have :
4 - TITI ==> OK
With IE, we have :
4 - TOTO ==> Why ? <snip>

The use of a javascript pseudo-protocol HREF. The general rule is; if
you use a javascript pseudo-protocol HREF (other than as a source of
content replacing HTML source code in the form of a javascript string)
all bets are off as to what will happen/function afterwards. They should
not ever be used in cross-browser scripting to execute side-effect
functions, or as null/void hrefs.

Change the line to:-

<A href="#" onclick="affName(4);return false;">window.name ?</A>

- and the window name reported is as expected.
Yours sincerely, Thierry


In English 'Yours sincerely' is used when you know (and have stated) the
name of the recipient of the communication, which cannot be true in this
case. 'Yours faithfully' is formally correct in this context (if maybe a
bit too formal).

Richard.
Jul 23 '05 #2

P: n/a
Bonjour à Richard Cornford qui nous a écrit :
Change the line to:-

<A href="#" onclick="affName(4);return false;">window.name ?</A>

- and the window name reported is as expected.


I'm sorry, but the result is exactly le same that with
"javascript:affName(4)". Even if you are right, it is not the solution
for my problem. Had you tried yourself ?
Yours sincerely, Thierry


In English 'Yours sincerely' is used when you know (and have stated)
the name of the recipient of the communication, which cannot be true
in this case. 'Yours faithfully' is formally correct in this context
(if maybe a bit too formal).

Richard.


Thank you for your comment...

--
Cordialement, Thierry ;-)

Jul 23 '05 #3

P: n/a
Cenekemoi wrote:
Richard Cornford wrote:
Change the line to:-
<A href="#" onclick="affName(4);return false;">window.name ?</A>

- and the window name reported is as expected.


I'm sorry, but the result is exactly le same that with
"javascript:affName(4)". Even if you are right, it is not
the solution for my problem. Had you tried yourself ?

<snip>

Of course I tried it. I had to verify that the code you posted exhibited
the symptoms described. As it did, and the javascript pseudo-protocol is
a notorious troublemaker, I experimented with moving the code to an
onclick handler, and the symptoms went away in IE 6.

Richard.
Jul 23 '05 #4

P: n/a
Cenekemoi wrote:
Bonjour à Richard Cornford qui nous a écrit : I'm sorry, but the result is exactly le same that with
"javascript:affName(4)". Even if you are right, it is not the solution
for my problem.

Cenekemoi,

the window.name attribute is DOM level 0, which means (I think) it is a legacy supported feature that existed prior to the formalisation of the DOM, hence support is problematic.

If you add a button to Page2.htm and check window.name *before* clicking your href link, you will see that "window.name" when the window is loaded is indeed set to TITI by the script in the header. When your link is clicked, "window.name" reverts to TOTO - clicking on the button after clicking on your link gives "TOTO" too.

All I can suggest is that you call window.name directly, do you need the affName function?
New Page2.htm

<html><head>
<script type="text/javascript">
function affName(i) {
alert( i +" - "+ window.name );
}
affName(1);
window.name = "TITI";
affName(2);
</script>
</head><body onload="affName(3);">
<form>
<input type="button" value="click"
onclick="alert(window.name);">
</form>
<br>
<a href="javascript:affName(4)">window.name ?</a>
</body></html>
Regards, Rob.
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.