submitting form multiple times

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;
}
 
D

David Mark

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

I certainly do not. I see that pattern used for all sorts of silly
(and unnecessary) workarounds. Are we talking about a frames
collection deficiency (as also seen with forms and elements in IE?)
If so, setting the name after appending the IFrame to the document may
alleviate the problem.

The contentWindow workaround is interesting (and certainly preferable
to proprietary createElement shenanigans.)
 

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
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top