473,857 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.create Element( 'iframe' );
this.iframe.id = this.id + 'wh';
this.iframe.sty le.display = 'none';
this.iframe.nam e = this.iframe.id; // <---

// snippage, including generation of the form

this.form.targe t = this.iframe.nam e;
this.form.appen dChild( this.iframe );
However, when I submit the form it opens in a new window.
When I alert( document.body.i nnerHTML ), 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.appen dChild( this.iframe )

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

* Setting this.form.targe t = 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 4876
Just use the "id" tag, and not the name tag. Refer to it as
dr436929wh.loca tion.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.loca tion.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.create Element( 'iframe' );
this.iframe.id = this.id + 'wh';
this.iframe.sty le.display = 'none';
this.iframe.nam e = this.iframe.id; // <---

// snippage, including generation of the form

this.form.targe t = this.iframe.nam e;
this.form.appen dChild( this.iframe );
However, when I submit the form it opens in a new window.
When I alert( document.body.i nnerHTML ), 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.setAttr ibute('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.create Element('<ifram e name="iframeNam e">')
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.create Element('<ifram e name="' + iframeName + '">');
}
catch (e) {
iframe = document.create Element('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.create Element('iframe ');
iframe.name = iframeName;
}
// now use iframe element here further

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4
ve***********@g mail.com wrote:
Just use the "id" tag, and not the name tag. Refer to it as
dr436929wh.loca tion.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.i nnerHTML ), 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.setAttr ibute('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.create Element('<ifram e name="iframeNam e">')


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.create Element('<ifram e name="' + iframeName + '">');
}
catch (e) {
iframe = document.create Element('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.create Element('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.create Element( 'iframe' );
this.iframe.id = this.id + 'wh';
this.iframe.sty le.display = 'none';
this.iframe.nam e = this.iframe.id;

this.form = document.create Element( 'form' );
this.form.targe t = this.iframe.nam e;
this.form.id = this.id + 'f';

if( document.all ) {
this.form.inner HTML += '<iframe id="' + this.iframe.id +
'" name="' + this.iframe.id +
'" style=display:n one;></iframe>';

} else
this.form.appen dChild( 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.create Element( 'iframe' );
this.iframe.id = this.id + 'wh';
this.iframe.sty le.display = 'none';
this.iframe.nam e = this.iframe.id;

this.form = document.create Element( 'form' );
this.form.targe t = this.iframe.nam e;
this.form.id = this.id + 'f';

if( document.all ) {
this.form.inner HTML += '<iframe id="' + this.iframe.id +
'" name="' + this.iframe.id +
'" style=display:n one;></iframe>';


I would change that to
if (this.form.inse rtAdjacentHTML) {
this.form.inser tAdjacentHTML(
'beforeEnd',
'<iframe id="' + ... + '<\/iframe>'
)
}
else {
this.form.appen dChild(this.ifr ame);
}
as IE's DOM (and even other browsers like Opera emulating IE's DOM) has
insertAdjacentH TML 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.create Element('form') ;
var input = document.create Element('input' );
input.name = 'inputName';
form.appendChil d(input);
alert(form.inne rHTML)

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
8139
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 title. I am trying to change the title of the IFrame window to be that of the contained window title. If I uncomment the alert statement below - the title change works. Comment out the alert - and - no title change.
3
2618
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 enough, right? e.g. this successfully sets the local form's field: document.thetestform.mycity.value='paris';
15
20591
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 name="textarea" cols=80 rows=18> This is a test </textarea><br>
3
4044
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 IsPostBack=False by now!. The ASPX is opened via client side script (into an iFrame) inside a .HTM file (as ASPX postback causes problems in a modal internet explorer dialog if not in an iFrame!) Anyone know how to get around this - i need to...
1
3062
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 they will co-operate if there are small things they need to do in their code, like putting something in the body tag or adding some script, though I would ideally like everything to be done in this page, and not in their pages). ...
2
3285
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 quicktime or windows meida player depending on which plugin was found. after the plug in is found a iframe with the right player is created. here is the code. for some reason In IE the plug in doesnt work and in fire fox it crashes <!DOCTYPE html...
0
7782
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 explorer but not on firefox. I dont want it to scroll sideways. in index.htm the iframe is at the bottom of the code. index.htm <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">...
3
2932
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 selecting the genre the artists appears in iframe1...and i want to be able to select the artist so that the songs appear. I am unsure of how to do this, could anybody help? Thanks Here is my current code... <html> <head> <title>MiTunes</title>...
0
9923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11082
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10711
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10394
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9549
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7939
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7104
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5774
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4190
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.