473,756 Members | 4,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DOM Created Elements / Cross Frame Scripting Problem. Firefox

Using the following example:

domiframetest.h tml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<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.create Element('iframe ');
Iframe.id = 'DOMIframe';
Iframe.name = 'DOMIframe';
Iframe.src = 'functiontest.h tml';
Iframe.style.he ight = '60px';
Iframe.style.wi dth = '200px';
Iframe.style.bo rder = '1px solid #ff0000';
document.body.a ppendChild(Ifra me);
}
function destroyIframe() {
document.body.r emoveChild(docu ment.getElement ById('DOMIframe '));
}

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

</script>
</head>

<body>
<input name="Create Iframe" type="button" value="Create Iframe"
onclick="create Iframe(); return false" /> <input name="Destroy Iframe"
type="button" value="Destroy Iframe" onclick="destro yIframe(); return
false" /> <input name="Test Iframe Function" type="button" value="Test
Iframe Function" onclick="testIf rameFunction(); return false" /><br />
</body>
</html>
[/code]

functiontest.ht ml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Functi on 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.doAle rt 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.fra mes['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 9561
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.nam e = 'DOMIframe';" line does nothing but
break the "window.fra mes['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.getEle mentById("DOMIf rame").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.getEle mentById("DOMIf rame") 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.getEle mentById("DOMIf rame").contentW indow.myFunctio n(); 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.nam e = '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.l ength loop doesn't seem too outrageous. Still, it would
be nice to have an ID shortcut.

VK wrote:
Commenting out the "Iframe.nam e = '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 "instabilit y bug" to Mozilla
(bugzilla.mozil la.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.javas cript :-(

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
4365
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 registered with www.mydomain.com and is stealth forwarded to www.ccthecomputerguy.com (where my *real* web site currently lives). FWIW, I do this because in the 8+ years I've been on the web, I've changed ISPs about 5 times and every change requires a...
7
3914
by: Scott M. | last post by:
How can I disable the cross-site scripting check for one particular page of a site?
3
10202
by: Vongza | last post by:
<html> <head> <title>Cross Frame Reference</title> <script language="javascript"> function showThisTitle() { alert(document.title); } function showAnotherTitle() { try { alert(anotherWorld.document.title);
9
5443
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 answer or solution for this? I'm trying to do this: top.frames.location.reload(); Thanks Mark Howells www.permanenttourist.ch
4
2952
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 includes a form that accepts the name of a web site (example: www.foo.com), which a script or perhaps a "target" attribute then loads into frame 2 b) frame 1 waits for frame 2 to load, then reads (for example)
1
1795
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 concerning cross- domain-scripting. Our first soultion (which is working) uses the setting of the required privilege to have "Universal BrowserReas" netscape.security.PrivilegeManager.enablePrivilege ("UniversalBrowserRead");
2
1871
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. however, this cross-frame scripting security with IE is really getting on my nerves. i can't even use VB to navigate to frames located on a different domain. the page in question uses framesets, not iframes. question: how can i DISABLE the horrid...
0
1241
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 site (non-intranet) and loading it into a table. however, this cross-frame scripting security with IE is getting in the way. i can't even use VB to navigate to frames located on a different domain. the website in question uses framesets, not iframes. ...
3
2684
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 write some code in a page in website B so that i can do cross frame scripting. This worked fine in my environment. But this did not work when i tried the same on our server. Are there any other conditions apart from 'Same domain' that would...
0
9255
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10014
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...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9689
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
8688
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...
0
6514
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
5119
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...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3326
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.