J
Jorge
That is the documented behaviour if no name was found,
| If there is no existing window or frame with the same name as
| specified in the target, a new window is opened with a name equal to
| the value of the target.
<http://msdn.microsoft.com/en-us/library/ms534659(VS.85).aspx>
so the first thing to check – if you don’t already know that you cannot
set the name property for a dynamically created IFRAME element – would
be if there’s a name attribute set. There isn’t.
The above excerpt already points to a workaround:
iframe.contentWindow.name = iframe.id = 'fubar';
(unless you prefer the silly
document.createElement('<element attribute="value">')
borkaround
Yes, that works. Thanks. I've found another 2 workarounds:
function newTargetIFrame (n) {
var id= "n"+ n;
/*
//Should be:
targetIFrame= document.createElement('iframe');
targetIFrame.name= targetIFrame.id= id;
document.body.appendChild(targetIFrame);
//... but it fails in IE6-7
*/
/*
//One possible IE6-7 hack:
try {
targetIFrame= document.createElement('<iframe name="'+ id+ '">');
} catch (e) {
targetIFrame= document.createElement('iframe');
targetIFrame.name= id;
}
*/
/*
//Another IE6-compatible workaround:
var e= document.body.appendChild(document.createElement('span'));
e.innerHTML= '<iframe name="'+ id+ '" id="'+ id+ '">';
*/
//Eic Bedndarz proposed IE6-7 hack:
targetIFrame= document.createElement('iframe');
targetIFrame.name= targetIFrame.id= id;
document.body.appendChild(targetIFrame);
try {
targetIFrame.contentWindow.name= id;
} catch (e) {
}
return id;
}