473,789 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing an IFrame's properties

Hi,

I want to access the properties of an IFrame but seem unable to get access
to the IFrames document body.

<html>

<body>
<iframe src="test.html" id="IFrame"></iframe>
</body>

<script>
var f = document.getEle mentById('IFram e');
f.document.body .innerHTML = "This is another test";
</script>

</html>

This writes to the main document not the IFrame.

I am doing something very basic wrong but cannot work out what. (I do know I
should be doing a open/write/close rather than an innerHTML but this is just
for testing access to the contained IFrames properties)

Help,

Aaron
Apr 5 '06 #1
14 18292
Aaron Gray wrote:
I want to access the properties of an IFrame but seem unable to get access
to the IFrames document body.

<html>

<body>
<iframe src="test.html" id="IFrame"></iframe>
</body>

<script>
var f = document.getEle mentById('IFram e');
f.document.body .innerHTML = "This is another test";
</script>

</html>

This writes to the main document not the IFrame.
Of course.
I am doing something very basic wrong but cannot work out what.
You are obtaining a reference to an HTMLIFrameEleme nt object, representing
an `iframe' element node in the document tree. By modifying the former's
proprietary `innerHTML' property, you modify the content of the `iframe'
element. This content is displayed only if the `iframe' element is not
supported.
(I do know I should be doing a open/write/close rather than an innerHTML
but this is just for testing access to the contained IFrames properties)


You need to access the document object of the IFrame resource instead.

Proprietary: window.frames['IFrame'].document
(preferably with `name' instead)
<URL:http://research.nihons oft.org/javascript/ClientReference JS13/frame.html>
<URL:http://msdn.microsoft. com/workshop/author/dhtml/reference/objects/obj_window.asp>

Standards compliant: f.contentDocume nt
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-50708718>

Similar questions have been asked here before.
PointedEars
Apr 5 '06 #2
> I want to access the properties of an IFrame but seem unable to get access
to the IFrames document body.


Properties are accessable but content is not on IE 6, previous versions
allowed access to the contents.

Firefox allows access to the contents of an IFrame, but IE6 does not.

Aaron
Apr 5 '06 #3
Aaron Gray wrote:
I want to access the properties of an IFrame but seem unable to get
access to the IFrames document body.


Properties are accessable but content is not on IE 6, previous versions
allowed access to the contents.

Firefox allows access to the contents of an IFrame, but IE6 does not.


Nonsense.
PointedEars
Apr 5 '06 #4
>> Properties are accessable but content is not on IE 6, previous versions
allowed access to the contents.

Firefox allows access to the contents of an IFrame, but IE6 does not.


Nonsense.


Try it and please send me some code that disputes this !

I would be most greatful if you can prove me wrong.

Aaron
Apr 5 '06 #5
Aaron Gray wrote:
Properties are accessable but content is not on IE 6, previous versions
allowed access to the contents.

Firefox allows access to the contents of an IFrame, but IE6 does not.


Nonsense.


Try it and please send me some code that disputes this !

I would be most greatful if you can prove me wrong.


<URL:http://pointedears.de/scripts/test/dom/iframe>
PointedEars
Apr 5 '06 #6
>>>> Properties are accessable but content is not on IE 6, previous versions
allowed access to the contents.

Firefox allows access to the contents of an IFrame, but IE6 does not.

Nonsense.


Try it and please send me some code that disputes this !

I would be most greatful if you can prove me wrong.


<URL:http://pointedears.de/scripts/test/dom/iframe>


I seem to be able to read but not modify innerHTML.

I'll modify my statement :-

IFrame content is readable but not modifiable from the parent
window.

Do you agree ?

Thurther :-

<iframe src="document.h tml" name="IFrame" id="IFrame"></iframe>
<div id="sourceViewD iv"></div>

document.getEle mentById("sourc eViewDiv").inne rHTML =
window.frames['IFrame'].document.body. innerHTML;
window.alert(wi ndow.frames['IFrame'].document.body. innerHTML);

The first script line fails but the alert works.

Am very confused,

Aaron
Apr 5 '06 #7
Please provide attribution of quoted material, as described in
the Netiquette Guidelines (RFC1855) and the newsgroup's FAQ.[1]
vvvvvvvvvvvvvvv vv
Aaron Gray wrote:
> Properties are accessable but content is not on IE 6, previous
> versions allowed access to the contents.
>
> Firefox allows access to the contents of an IFrame, but IE6 does not.
Nonsense.
Try it and please send me some code that disputes this !

I would be most greatful if you can prove me wrong. <URL:http://pointedears.de/scripts/test/dom/iframe>


I seem to be able to read but not modify innerHTML.


I overlooked that part.
I'll modify my statement :-

IFrame content is readable but not modifiable from the parent
window.

Do you agree ?
That would depend on what you call "IFrame content". Try the URL again
(I modified the document). The first and third button do work for me in
IE 6.0 SP1 [Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)]. All
buttons work in Firefox 1.5.0.1 [Mozilla/5.0 (X11; U; Linux i686; en-US;
rv:1.8.0.1) Gecko/20060313 Debian/1.5.dfsg+1.5.0. 1-4 Firefox/1.5.0.1].
Thurther :-

<iframe src="document.h tml" name="IFrame" id="IFrame"></iframe>
<div id="sourceViewD iv"></div>

document.getEle mentById("sourc eViewDiv").inne rHTML =
window.frames['IFrame'].document.body. innerHTML;
It does not appear as if you were attempting to modify the IFrame
document content here.
window.alert(wi ndow.frames['IFrame'].document.body. innerHTML);

The first script line fails but the alert works.


ISTM either you have mixed up the sides of the assignment, or you have
described the wrong problem. If the latter, you should make sure that
you are operating on a Valid document first[2], and that
document.getEle mentById(...) returns an element object reference.[3]
"The first script line fails" is no error report.[4]
PointedEars
___________
[1] <URL:http://jibbering.com/faq/>
[2] <URL:http://validator.w3.or g/>
[3] <URL:http://pointedears.de/scripts/test/whatami#inferen ce>
[4] <URL:http://jibbering.com/faq/#FAQ4_43>
Apr 5 '06 #8
> "Thomas 'PointedEars' Lahn" <Po*********@we b.de> wrote:
news:85******** ********@Pointe dEars.de....
[snip]

That would depend on what you call "IFrame content". Try the URL
again (I modified the document). The first and third button do
work for me in IE 6.0 SP1 [Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.0)]. All buttons work in Firefox 1.5.0.1 [Mozilla/5.0
(X11; U; Linux i686; en-US; rv:1.8.0.1) Gecko/20060313
Debian/1.5.dfsg+1.5.0. 1-4 Firefox/1.5.0.1].

[snip]
How would it work in all them browsers if you replace contentDocument
with contentWindow.d ocument?

--
BootNic Wednesday, April 05, 2006 4:15 PM

It's not that some people have willpower and some don't. It's that
some people are ready to change and others are not.
*James Gordon*

Apr 5 '06 #9
"Thomas 'PointedEars' Lahn" <Po*********@we b.de> wrote in message
news:85******** ********@Pointe dEars.de...
Please provide attribution of quoted material, as described in
the Netiquette Guidelines (RFC1855) and the newsgroup's FAQ.[1]
vvvvvvvvvvvvvvv vv
Aaron Gray wrote:
>> Properties are accessable but content is not on IE 6, previous
>> versions allowed access to the contents.
>>
>> Firefox allows access to the contents of an IFrame, but IE6 does not.
> Nonsense.
Try it and please send me some code that disputes this !

I would be most greatful if you can prove me wrong.
<URL:http://pointedears.de/scripts/test/dom/iframe>


I seem to be able to read but not modify innerHTML.


I overlooked that part.
I'll modify my statement :-

IFrame content is readable but not modifiable from the parent
window.

Do you agree ?


That would depend on what you call "IFrame content". Try the URL again
(I modified the document). The first and third button do work for me in
IE 6.0 SP1 [Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)]. All
buttons work in Firefox 1.5.0.1 [Mozilla/5.0 (X11; U; Linux i686; en-US;
rv:1.8.0.1) Gecko/20060313 Debian/1.5.dfsg+1.5.0. 1-4 Firefox/1.5.0.1].
Thurther :-

<iframe src="document.h tml" name="IFrame" id="IFrame"></iframe>
<div id="sourceViewD iv"></div>

document.getEle mentById("sourc eViewDiv").inne rHTML =
window.frames['IFrame'].document.body. innerHTML;


It does not appear as if you were attempting to modify the IFrame
document content here.


No just reading its text into a div.
window.alert(wi ndow.frames['IFrame'].document.body. innerHTML);

The first script line fails but the alert works.


ISTM either you have mixed up the sides of the assignment, or you have
described the wrong problem. If the latter, you should make sure that
you are operating on a Valid document first[2], and that
document.getEle mentById(...) returns an element object reference.[3]
"The first script line fails" is no error report.[4]


It was returning null.

Your example shows the modification of IFrame innerHTML working.

Looks like it is a timing error in my code. Doing mods explicitly to the
IFrame on loading the parent document causes a 'null' value for that
documents body.

Many thanks for your help Thomas,

Aaron

Apr 5 '06 #10

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

Similar topics

1
6484
by: Griff | last post by:
I am trying to write a program in VB6 to get at file properties (Owner, Title, etc ). I can access them using scripting, Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace("C:\") string= objFolder.GetDetailsOf(strFileName, n) but don't know how to then change them. Can anyone point me at a resource to explain how I can do this?
0
1148
by: TB | last post by:
(re-wording a previous post.. this makes much more sense, sorry for any duplication) First off, I've got three classes: Class MyItem Public PropertyOne As String Public PropertyTwo As String Public PropertyThree As String Public ItemError As MyItemError
1
1149
by: GautamKumar | last post by:
I want to access(SET) all the properties of IIS programmatically using C# I need to set the IIS properties through the code.plzz let me know wat class we have to use to access these properties or how i have to approach. Pls let me know if you have any hints regarding this.. Thanks GautamKumar
2
1221
by: chauncy | last post by:
Hi, I have a databound dropdown filled with data. The text value is a file path that I want to use to open that file in a new browser window. I can do this with a html dropdown because I can access the properties of that control from javascript. document.form.mydd.value
1
2419
by: Jeff Smith | last post by:
Can I load custom web user controls dynamically and access the properties and methods without having to explicitly define custom control types (example 2 below). I have custom web control named EditStuff.ascx which reads from an xml file and loads controls to its self based on string value in xml nodes collection of the xml. There are several controls that can be loaded and for each one there exists a public method called 'IntiControl'...
3
1131
by: BillGatesFan | last post by:
Alright, this is very strange. I call a javascript function in my page load that accesses an iframe and I get an error. But if I wait till the page completely loads and access the iframe through a click event everything works fine. I'm trying to set some of the iframe's properties on page load before the page gets rendered. Can I do this? I even tried to acess it in the Pre Render event and that does not work either. Thanks for help
0
2598
by: Bishop | last post by:
I've figured out how to create a custom TreeNode with custom properties and I can view those properties at runtime, but I'm not sure how to change them after I've added the custom node to the tree. For example: Public Class CustomTreeNode Inherits TreeNode
4
4020
by: evantay | last post by:
I'm using ASP.NET 2.0 with VS.NET 2005. I'm trying to access properties from my master pages within a page that inherits from that master page (a child page). However the values are always null. In my masterpage I have this: private bool m_AlreadyTested; public bool AlreadyTested { get { return m_AlreadyTested; }
0
1038
by: Matt Nunnally | last post by:
Hi, I have a DLL I created in .NET. I have certain exposed properties that I have exposed that are declared as Integer or Byte arrays. Trying to access those certain properties through unmanaged code (VB6 for example) throws the following error: Function uses an automation type not supported in Visual Basic. Is there a way of getting around this from the VB6 side without have to make any changes to the DLL code?
0
9511
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
10404
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
10195
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
9016
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
5415
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
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.