IE and window.name

C

Cenekemoi

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

Richard Cornford

Cenekemoi wrote:
<A href="javascript:affName(4)">window.name ?</A>
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.
 
C

Cenekemoi

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 ?
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...
 
R

Richard Cornford

Cenekemoi said:
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.
 
R

RobG

Cenekemoi said:
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.
 

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

Forum statistics

Threads
474,084
Messages
2,570,596
Members
47,217
Latest member
GuadalupeE

Latest Threads

Top