473,372 Members | 1,200 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,372 software developers and data experts.

DOM Created Elements / Cross Frame Scripting Problem. Firefox

Using the following example:

domiframetest.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>DOM Iframe Test</title>
<script type="text/javascript">
function createIframe(){
var Iframe = document.createElement('iframe');
Iframe.id = 'DOMIframe';
Iframe.name = 'DOMIframe';
Iframe.src = 'functiontest.html';
Iframe.style.height = '60px';
Iframe.style.width = '200px';
Iframe.style.border = '1px solid #ff0000';
document.body.appendChild(Iframe);
}
function destroyIframe(){
document.body.removeChild(document.getElementById( 'DOMIframe'));
}

function testIframeFunction(){
window.frames['DOMIframe'].doAlert();
}

</script>
</head>

<body>
<input name="Create Iframe" type="button" value="Create Iframe"
onclick="createIframe(); return false" /> <input name="Destroy Iframe"
type="button" value="Destroy Iframe" onclick="destroyIframe(); return
false" /> <input name="Test Iframe Function" type="button" value="Test
Iframe Function" onclick="testIframeFunction(); return false" /><br />
</body>
</html>
[/code]

functiontest.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Function Test</title>
<script type="text/javascript">
function doAlert(){
alert('Function Successful');
}
</script>
</head>

<body>
<p>Function Test</p>
</body>
</html>

I seem to be having a strange problem regarding a DOM created IFRAME
and cross frame scripting.

If I create an IFRAME with DOM and then try and access a function
within the IFRAME everything works as expected. The IFRAME's doAlert()
function fires, everyone is happy.

However, if I then remove the IFRAME element and recreate it, The
IFRAME's doAlert() function DOES NOT fire producing the error
"window.frames.DOMIframe.doAlert is not a function" and everyone is sad
:(

The really strange part is that I can initially create and remove the
IFRAME as many times as I want and the doAlert() function still fires.
As soon as I access the doAlert() function for the first time removing
/ recreating the IFRAME element will break the script.

Everything works as expected in IE, as long as the IFRAME is there, the
doAlert() function fires.

Using the same name / id for the IFRAME should be valid as my intention
is to only have one element created at a time. The Firefox DOM
inspector reports that the node is getting removed properly from the
DOM tree (so I am clearly not overlapping id's).

Which leads me to ???, my only guess is that my frame call is wrong
"window.frames['DOMIframe'].doAlert();" (I have tried numerous other
cross frame calls though) or Firefox has a bug that breaks that call
when your creating / removing DOM elements on the fly.

Any help would be appreciated.

Jul 23 '05 #1
6 9516
VK
> Using the same name / id for the IFRAME should be valid
But it's not, never was and really *is* your problem.
Simply comment out
Iframe.name = 'DOMIframe'; and it will start work.
as my intention is to only have one element created at a time.

You real intention is to somehow address an element later, this is why
on gives ID's or NAME's on the first place. Look at the mess you're
doing :-) You're using DOMIframe* as id reference in one line, and as
a name reference just a couple of lines below. IE is *very* tolerant,
up to the point it can barely understand your real intentions. FF is
not.

Jul 23 '05 #2
VK wrote:
Using the same name / id for the IFRAME should be valid But it's not, never was and really *is* your problem.


You actually missed my meaning here as I was trying to say that
re-using the same id would be valid because I would only have one
iframe element on the screen at the time.

However you seem to be indicating that having the same "value" for both
name and ID is technically invalid. Nothing in the W3 Standards for
both the DOM and XHTML states that you can not have the same
"value" for a name and id attribute. It only RECOMMENDS that you do
not use the same name and id for the <a> tag for obvious reasons. Any
element with the same name / id pair will validate fine in any W3
validator.

Additionally, if that were the case, I could simply change my code to:

Iframe.id = 'DOMIframe';
Iframe.name = 'DOMIframeName';

And everything should work fine, which it doesn't.
Simply comment out
Iframe.name = 'DOMIframe'; and it will start work.


Commenting out the "Iframe.name = 'DOMIframe';" line does nothing but
break the "window.frames['DOMIframe']" call which is based off the name
attribute.
as my intention is to only have one element created at a time.

You real intention is to somehow address an element later, this is why
on gives ID's or NAME's on the first place. Look at the mess you're
doing :-) You're using DOMIframe* as id reference in one line, and as
a name reference just a couple of lines below. IE is *very* tolerant,
up to the point it can barely understand your real intentions. FF is
not.


Again, there is nothing in the W3 standards that states I can not
reference an element by ID then reference it by NAME, or vise-versa, or
any combination thereof. This is a perfectly valid practice, just not
an ideal one. My choice to use window.frames['DOMIframe'] was simply
one based on browser compatibility, all the current major browsers
support it. I had tried document.getElementById("DOMIframe").function()
but that was a no go because it's not referencing the document inside
of it, which is why I posted here for suggestions.

Additionally, if it was simply a tolerance issue for Firefox, then it
wouldn't work the first time, which is does. It only breaks after you
remove an element and recreate it. You would know that if you tested my
code before you replied (and you would have known your solution
doesn't work either).

Turns out I was very close to my solution, I only had to add
..contentWindow to the end of document.getElementById("DOMIframe") to
reference the document inside of it. Unfortunately this method is not
100% compatible with Opera or Safari but I found a work around here:
http://xkr.us/articles/dom/iframe-document/

So the end result for Firefox is
document.getElementById("DOMIframe").contentWindow .myFunction(); and I
eliminate the "mess" as you call it.

Thanks for the reply though, even if it was invalid.

Jul 23 '05 #3
VK
> Commenting out the "Iframe.name = 'DOMIframe';" line does nothing

I'm sorry, I have forgotten to mention that I also changed the frame
addressing to the right one. So I did two changes in your original
code:

1) comment out
// Iframe.name = 'DOMIframe';

2) change
window.frames['DOMIframe'].doA*lert();
to
window.frames[0].doA*lert();

After that it worked as a charme on FF 1.4, no matter how many times I
added/removed/added iframe (calling doAlert() after each cicle).

I guess we can talk about an over-sensivity in FF though. It should(?)
let users go with a little stuff like that.

Jul 23 '05 #4
Ahh. Thanks for the heads up on that window.frames[0] call, that is a
much nicer solution as it appears that it also supported in all the
current major browsers.

So I guess my next question would be, is it possible (and reliable) to
get the number of the frame without going through a loop to find the
correct id?

I am just looking to reduce runtime overhead but in the case of frames
I certainly don't plan on having many on a page so I guess a
window.frames.length loop doesn't seem too outrageous. Still, it would
be nice to have an ID shortcut.

VK wrote:
Commenting out the "Iframe.name = 'DOMIframe';" line does nothing


I'm sorry, I have forgotten to mention that I also changed the frame
addressing to the right one. So I did two changes in your original
code:

1) comment out
// Iframe.name = 'DOMIframe';

2) change
window.frames['DOMIframe'].doA*lert();
to
window.frames[0].doA*lert();

After that it worked as a charme on FF 1.4, no matter how many times I
added/removed/added iframe (calling doAlert() after each cicle).

I guess we can talk about an over-sensivity in FF though. It should(?)
let users go with a little stuff like that.


Jul 23 '05 #5
VK
> Still, it would be nice to have an ID shortcut.

It should, and you could file an "instability bug" to Mozilla
(bugzilla.mozilla.org). But I'm affraid that it doesn't help too much
on your *current* project. The root problem is that IFRAME's hierarhy
is not well defined, as it appeared as a rather new extension of
WINDOW. I'm sorry for being too lazy to type in all underground issues,
but if you really want to know them, I can answer it within a week or
so (summer, man ;-)
Actually it's a remote - but direct - issue of <FAQENTRY> tread
question you may see now in this group (where I'm almost bit down by
the best selected people of comp.lang.javascript :-(

I would stay on the loop for now (unless 50-100 ms time gain is
important in your project).

Jul 23 '05 #6
No Problem, enjoy the summer :), and thanks again for the info.

Jul 23 '05 #7

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

Similar topics

6
by: Charles Crume | last post by:
Hello; My index.htm page (www.charlescrumesoftware.com for those interested in looking) contains 3 frames (left = content, top right = logo, bottom right = navigation). This domain name is...
7
by: Scott M. | last post by:
How can I disable the cross-site scripting check for one particular page of a site?
3
by: Vongza | last post by:
<html> <head> <title>Cross Frame Reference</title> <script language="javascript"> function showThisTitle() { alert(document.title); } function showAnotherTitle() { try {...
9
by: permanent.tourist | last post by:
I'm having a hell of a job getting this to work in Safari: the only thing I can think of is that one can't use reload() across to another frame for security reasons. Does anyone have a concrete...
4
by: taoberly | last post by:
Hello, Is it possible to run an HTML file from "localhost" and bypass the various security checks in place for cross-frame scripting? For example, on a 2-frame page loaded locally: a) frame...
1
by: torsten.reiners | last post by:
Hi, We try to implement a "web-application" where we have to access a general web-site -- loaded into a frame -- from another frame using JavaScript. We know that there are security issues...
2
by: KZSteele | last post by:
hello - i am using VBA within a microsoft access project to automate internet explorer. what i am doing is reading data from various frames in the IE window and loading them into a table. ...
0
by: KZSteele | last post by:
(repost/edit from html forum) hello - i am using VBA within a microsoft access project to automate internet explorer. what i am doing is reading data from various frames of my company's web...
3
by: dotpranay | last post by:
Hi, I have two websites in my local IIS. Website A and B. A runs under SSL and B does not. A has a page that has an iframe showing B in that iframe. Both sites being on the same domain. i could...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.