contentwindow & contentdocument

contentDocument

 

Definition and Usage:

The contentDocument property returns the Document object generated by a frame or iframe element.

This property can be used in the host window to access the Document object that belongs to a frame or iframe element.

Note: Because of security reasons, the contents of a document can be accessed from another document only if the two documents are located in the same domain.

 

Syntax: 

frameObject.contentDocument or iframeObject.contentDocument

 

eg:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>

<script type="text/javascript">

function changeStyle()

{

var x=document.getElementById("myframe");

var y=(x.contentWindow || x.contentDocument);

if (y.document)y=y.document;

y.body.style.backgroundColor="#0000ff";

}

</script>

</head>

<body>

 

<iframe id="myframe" src="demo_iframe.htm">

<p>Your browser does not support iframes.</p>

</iframe>

<br /><br />

<input type="button" οnclick="changeStyle()" value="Change background color" />

</body>

</html>

  

contentWindow

 

Definition and Usage:

The contentWindow property returns the Window object generated by a frame or iframe element (through the window object, you can access the document object and then any one of the document's elements).

 

Syntax: 

frameObject.contentWindow or iframeObject.contentWindow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值