访问IFrame的属性 [英] Accessing an IFrame's properties

查看:87
本文介绍了访问IFrame的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想访问IFrame的属性,但似乎无法访问到IFrames文档正文的




< html>


< body>

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

< / body>


< script>

var f = document.getElementById(''IFrame'');

f.document.body.innerHTML ="这是另一个测试;

< / script> ;


< / html>


这写入主文件而不是IFrame。


我正在做一些非常基本的错误,但无法解决问题。 (我知道我

应该是打开/写入/关闭而不是innerHTML,但这只是

用于测试对包含的IFrames属性的访问权限)


帮助,


Aaron

解决方案

Aaron Gray写道:

我想访问IFrame的属性,但似乎无法访问IFrames文档正文。

< html>

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

< script>
var f = document.getElementById(''IFrame'' );
f.document.body.innerHTML ="这是另一个测试;
< / script>

< / html>


当然。

我正在做一些非常基本的错误,但无法解决问题。


您正在获取对HTMLIFrameElement对象的引用,表示文档树中的iframe元素节点。通过修改前者的'b $ b专有`innerHTML''属性,可以修改`iframe''

元素的内容。仅当iframe元素不支持
时才会显示此内容。

(我知道我应该进行开放/写入/关闭而不是innerHTML
但这仅用于测试对包含的IFrames属性的访问权限)




您需要访问IFrame资源的文档对象。


所有权:window.frames [''IFrame'']。文件

(最好用'name'代替)

< URL :http://research.nihonsoft.org/javascript/ClientReferenceJS13/frame.html>

< URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/objects /obj_window.asp>


符合标准:f.contentDocument

< http://www.w3.org/TR/DOM-Level-2 -HTML / html.html#ID-50708718>


此前有人提出类似的问题。

PointedEars


>我想访问IFrame的属性,但似乎无法访问IFrames文档正文




属性可访问但内容不在IE 6上,以前的版本

允许访问内容。


Firefox允许访问IFrame的内容,但IE6不允许。


Aaron


Aaron Gray写道:

我想访问IFrame的属性,但似乎无法访问IFrames文档正文。



属性是可访问的,但内容不在IE 6上,以前版本
允许访问内容。

Firefox允许访问IFrame的内容,但IE6不允许。




胡说八道。

PointedEars


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.getElementById(''IFrame'');
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

解决方案

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.getElementById(''IFrame'');
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 HTMLIFrameElement 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.nihonsoft.org/javascript/ClientReferenceJS13/frame.html>
<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_window.asp>

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

Similar questions have been asked here before.
PointedEars


> 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


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


这篇关于访问IFrame的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆