473,249 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,249 software developers and data experts.

Setting iframe name in script

I'm trying to use a script-generated form to submit to a
script-generated iframe. The problem I'm running into is that the
iframe is not assuming the name I assign it.

IE6 on Win2000. FF1.0.2+ doesn't seem to have the problem.

I'm doing:
this.iframe = document.createElement( 'iframe' );
this.iframe.id = this.id + 'wh';
this.iframe.style.display = 'none';
this.iframe.name = this.iframe.id; // <---

// snippage, including generation of the form

this.form.target = this.iframe.name;
this.form.appendChild( this.iframe );
However, when I submit the form it opens in a new window.
When I alert( document.body.innerHTML ), I am being told:

<IFRAME id=dr436929wh></IFRAME>
[sic]
i.e. no "name" attribute (hence the new window).
What I've already tried:
* Setting the iframe.name attribute only after
this.form.appendChild( this.iframe )

* Using this.iframe.setAttribute( name, ... ) prior to and after the
appendChild

* Setting this.form.target = this.iframe (just for the hell of it)
Thanks in advance. I know you guys are good. Let me know if you need
more info.

Jul 23 '05 #1
7 4804
Just use the "id" tag, and not the name tag. Refer to it as
dr436929wh.location.href = "Whatever". Or, you can assign it's name
like this: dr436929wh.name = "Something". Try that and see if it works.

Jul 23 '05 #2
Just use the "id" tag, and not the name tag. Refer to it as
dr436929wh.location.href = "Whatever". Or, you can assign it's name
like this: dr436929wh.name = "Something". Try that and see if it works.

Jul 23 '05 #3


Christopher J. Hahn wrote:
I'm trying to use a script-generated form to submit to a
script-generated iframe. The problem I'm running into is that the
iframe is not assuming the name I assign it.

IE6 on Win2000. FF1.0.2+ doesn't seem to have the problem.

I'm doing:
this.iframe = document.createElement( 'iframe' );
this.iframe.id = this.id + 'wh';
this.iframe.style.display = 'none';
this.iframe.name = this.iframe.id; // <---

// snippage, including generation of the form

this.form.target = this.iframe.name;
this.form.appendChild( this.iframe );
However, when I submit the form it opens in a new window.
When I alert( document.body.innerHTML ), I am being told:

<IFRAME id=dr436929wh></IFRAME>
[sic]
i.e. no "name" attribute (hence the new window).


This is a known and documented shortcoming of IE on Win that can be
quite crippling to any effort to elegantly use DOM scripting in the
browser. For some reasons setting the name property (e.g. element.name =
expression) or name attribute (e.g. element.setAttribute('name',
expression) on a dynamically created element does not work in IE/Win so
you are forced to use the very ugly IE specific workaround of doing
var iframe = document.createElement('<iframe name="iframeName">')
However some browsers (notably Mozilla) will throw an error on that
argument to createElement so you have to use try/catch e.g.
var iframeName = 'iframeName';
var iframe;
// try IE way first
try {
iframe = document.createElement('<iframe name="' + iframeName + '">');
}
catch (e) {
iframe = document.createElement('iframe');
iframe.name = iframeName;
}
// now deal with browsers like Opera with do not throw an error
// but might return null or an unusable element
if (!iframe || iframe.tagName.toLowerCase() != 'iframe' ||
iframe.name != iframeName) {
iframe = document.createElement('iframe');
iframe.name = iframeName;
}
// now use iframe element here further

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4
ve***********@gmail.com wrote:
Just use the "id" tag, and not the name tag. Refer to it as
dr436929wh.location.href = "Whatever". Or, you can assign it's name
like this: dr436929wh.name = "Something". Try that and see if it works.


Micro: Thanks for the response. I tried a couple variants of your
suggestion but it refused to set the name attribute. Unfortunately,
this is a must as the form will often require POST for Apache logging
reasons. I ended up directly modifying the form's innerHTML as an IE
special case to put the iframe in there, name="..." included.

Thanks again.

Jul 23 '05 #5
Martin Honnen wrote:
Christopher J. Hahn wrote:
I'm trying to use a script-generated form to submit to a
script-generated iframe. The problem I'm running into is that the
iframe is not assuming the name I assign it.

IE6 on Win2000. FF1.0.2+ doesn't seem to have the problem. [snip]
However, when I submit the form it opens in a new window.
When I alert( document.body.innerHTML ), I am being told:

<IFRAME id=dr436929wh></IFRAME>
[sic]
i.e. no "name" attribute (hence the new window).
This is a known and documented shortcoming of IE on Win that can be
quite crippling to any effort to elegantly use DOM scripting in the
browser. For some reasons setting the name property (e.g. element.name =
expression) or name attribute (e.g. element.setAttribute('name',
expression) on a dynamically created element does not work in IE/Win so
you are forced to use the very ugly IE specific workaround of doing
var iframe = document.createElement('<iframe name="iframeName">')


Nice trick-- I like that one much better than what I ended up using.
I'm going to give this a shot because it's far more elegant than
appending the iframe tag to the form's innerHTML.

IE didn't have a problem setting the names of form fields, so I'm
wondering if this is a case of "If it has an ID, what's it need a name
for?" or whether form fields are a special case (for obvious reasons).
However some browsers (notably Mozilla) will throw an error on that
argument to createElement so you have to use try/catch e.g.
var iframeName = 'iframeName';
var iframe;
// try IE way first
try {
iframe = document.createElement('<iframe name="' + iframeName + '">');
}
catch (e) {
iframe = document.createElement('iframe');
iframe.name = iframeName;
}
// now deal with browsers like Opera with do not throw an error
// but might return null or an unusable element
if (!iframe || iframe.tagName.toLowerCase() != 'iframe' ||
iframe.name != iframeName) {
iframe = document.createElement('iframe');
iframe.name = iframeName;
}
// now use iframe element here further

--

Martin Honnen
http://JavaScript.FAQTs.com/


Excellent suggestion, and I will be trying it out. If you're
interested, I'll post the results of my attempts.

This what I'm using now (with impertinent code snipped):
this.id = 'dr' + Math.round( Math.random() * 1000000 );
this.iframe = document.createElement( 'iframe' );
this.iframe.id = this.id + 'wh';
this.iframe.style.display = 'none';
this.iframe.name = this.iframe.id;

this.form = document.createElement( 'form' );
this.form.target = this.iframe.name;
this.form.id = this.id + 'f';

if( document.all ) {
this.form.innerHTML += '<iframe id="' + this.iframe.id +
'" name="' + this.iframe.id +
'" style=display:none;></iframe>';

} else
this.form.appendChild( this.iframe );
Inelegant, but it works.

Jul 23 '05 #6


Christopher J. Hahn wrote:

This what I'm using now (with impertinent code snipped):
this.id = 'dr' + Math.round( Math.random() * 1000000 );
this.iframe = document.createElement( 'iframe' );
this.iframe.id = this.id + 'wh';
this.iframe.style.display = 'none';
this.iframe.name = this.iframe.id;

this.form = document.createElement( 'form' );
this.form.target = this.iframe.name;
this.form.id = this.id + 'f';

if( document.all ) {
this.form.innerHTML += '<iframe id="' + this.iframe.id +
'" name="' + this.iframe.id +
'" style=display:none;></iframe>';


I would change that to
if (this.form.insertAdjacentHTML) {
this.form.insertAdjacentHTML(
'beforeEnd',
'<iframe id="' + ... + '<\/iframe>'
)
}
else {
this.form.appendChild(this.iframe);
}
as IE's DOM (and even other browsers like Opera emulating IE's DOM) has
insertAdjacentHTML to efficiently parse a snippet of HTML and insert the
resulting nodes whereas your approach of innerHTML += requires reparsing
the existing content.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #7

Christopher J. Hahn wrote:
IE didn't have a problem setting the names of form fields, so I'm
wondering if this is a case of "If it has an ID, what's it need a name
for?" or whether form fields are a special case (for obvious reasons).


The problem with name exists for form controls too e.g. try

var form = document.createElement('form');
var input = document.createElement('input');
input.name = 'inputName';
form.appendChild(input);
alert(form.innerHTML)

with IE/Win and you see that the name attribute is not there. But
somehow IE manages to submit those form controls properly nevertheless
so you only run into problems when you want to access them by script
where you often get away with setting the id besides the name.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Russell | last post by:
I have a quirky issue that I believe involves timing and only 2 hairs left to pull. I have a modal dialog that is an IFrame. The IFrame contains another window - which contains the appropriate...
3
by: Bob | last post by:
I'm a total newbie at Javascript, but a programmer for over 20 years... so, my plans may be bigger than they are possible. I'm trying to set with Javascript the value of a form field... easy...
15
by: Aaron Gray | last post by:
<iframe name="iframe" width="100%" height="25%" src="test1.txt"> </iframe> <a href="test1.txt" target="input">one</a> <a href="test2.txt" target="input">two</a> <form name="form1"> <textarea...
3
by: Stevie_mac | last post by:
It might be me but... I dont seem to get a Page_Load event when a opening an ASPX in an iFrame. I do geta Page_Load event when an item on the ASPX (inside the iFrame) is clicked but then...
1
by: knkk | last post by:
Hi, I have an iframe that fetches content from a different domain. This is my URL, which has an iframe that fetches content from another site careerbuilder.co.in (this is a partnership channel, so...
2
riptide2049
by: riptide2049 | last post by:
I really have a problem here. I have a code that is suppost to take the href of a link from the right class;value of a link maked toreturn false. the value is a Media file the file is sent to...
0
by: tequilamala | last post by:
I have an Iframe in one of the pages i am developing... the iframe is suppose to scroll up and down and the links target the iframe. the problem is that the iframe scrolls side to side on internet...
3
by: matwilko | last post by:
hi, i am trying to create a simple version of itunes...and i am using iframes to do this. I have already set up the iframes using dreamweaver and used a drop-down menu to select the genre. When...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.