Laurent said:
Henry a écrit :
Oh come on ! Do you really need to be another PointedEars ?
You may not appreciate how the discipline of asking a decent question
promotes both understanding and eliciting worthwhile answers, but it
looks like you might get a lesson in that today.
LOL, really without any IE6/IE7 hack ?
That depends on what you consider an IE hack. The code I use works
fine on a very wide range of browsers including IE 6+ and does not
branch at all. It does take one action that is necessary to get it
working properly for IE, but that action is harmless to other
browsers.
I doubt it. No, sorry, I have no
doubt, I *know* by experience it is a lie.
So you *know* it is a lie? We will see.
<snip>
Microsoft's browser documentation is notoriously unreliable. And
they certainly are not (and never have been) a source for
cross-browser coding advice.
In IE6 and IE7, if you have to use the name attribute of a
dynamic element inserted into the document, you *must*
declare the name attribute of the element when calling
document.createElement(). After is too late.
There is no "must" about it.
in IE6 and IE7 :
var input = document.createElement('<input name="myInput">');
var iframe = document.createElement('<iframe name="myIframe">');
Anywhere else :
var input = document.createElement('input');
input.name = 'myInput';
This is successful in IE. The created input element is functional
and will be successfully submitted as a name/value pair with the
containing form. Here the issue with name attributes is only that
form controls created in this way are not then available as
members of the document, FORM element or its - elements -
collection using their names, but there are ways around that.
(The exception being <input type="radio">, which use name
attributes as part of their mechanism and so are problematic on
IE).
var iframe = document.createElement('iframe');
iframe.name = 'myIframe';
Period.
When properly analysed, to the point of precisely pinning down the
cause and effect relationship that results in the issue, the
critical factor is that when an IFRAME element is created on IE
without a name being provided in the creation process (the call
to - createElement -) the window object that corresponds with the
IFRAME is not given a - name - property, and subsequent setting
of the - name - property of the IFRAME object or its NAME
attribute (with setAttribute) does not have the side effect of
setting the - name - attribute of the window object.
Having pinned that down the solution is simple; it is to directly
assign to the - name - property of the window object, either just
before targeting it with links or form submission, or following
the IFRAMEs insertion into the document. E.G.:-
<html>
<head>
<title></title>
</head>
<body>
<a href="
http://www.google.com/"
target="myIframe"
onclick="frames[this.target].name = this.target">link</a>
<script type="text/javascript">
var iframe = document.createElement('iframe');
iframe.id = iframe.name = 'myIframe';
document.body.appendChild(iframe);
</script>
</body>
</html>
- and/or:-
<html>
<head>
<title></title>
</head>
<body>
<a href="
http://www.google.com/"
target="myIframe"
onclick="frames[this.target].name = this.target">link</a>
<script type="text/javascript">
var iframe = document.createElement('iframe');
iframe.id = iframe.name = 'myIframe';
document.body.appendChild(iframe);
frames['myIframe'].name = 'myIframe';
</script>
</body>
</html>
And those work fine on IE, many other browsers (the scriptable ones
that support dynamic DOM standard IFRAME creation) and does not
need to test and branch, while only using the standard call to -
createElement -. The window - name - setting operations are harmless
on the browsers that do not need them, and so it is easier/quicker
to just do it rather than trying to perform some test to see if it
is necessary, though the test is simple as prior to the assignment
the IE window object has no name. The same solution applies in
precisely the same way to form submission.
But of course your experience tells you that that is all a lie,
doesn't it? Period.