`

iframe的属性:document和Document以及Document的属性和iframe在各个浏览器获得内部文档的写法

 
阅读更多
.document引用到是的 iframe所在页面对象,
.Document (大写D),才能引用到iframe内含对象
<html>
<head>
<script>
function SetCwinHeight(obj)
{
// alert(obj.document.getElementById("tDiv").innerText);//可以获得当前页面id为tDiv的div的值
 alert(obj.Document.all.tDiv.innerText);
//这个可以获得text.html里面id为tDiv的div的值、、、
}
</script>
</head>
<body>
<iframe src="test.html" onload="SetCwinHeight(this);" width="600px' id="myframe" 
name="myframe">
</iframe>
<div id="tDiv">
tdiv
</div>
</body>
</html
>
test.html
...
<div id="tDiv" name="tDiv">sdiv</div>
...

下面是兼容ie,ff。chome等的写法
、
function SetCwinHeight()
{
  var obj=document.getElementsByTagName("iframe")[0];
 // var obj2=document.getElementById("myframe");//chome和firefox不支持id取iframe
  //alert(obj2);
  var str="";
  var cwin=obj;
  var sobj=null;
  if (document.getElementById){
    if (cwin && !window.opera){
      if (cwin.contentDocument){
       sobj = cwin.contentDocument; //FF NS
       alert("ff or chome");
       }
      else if(cwin.Document){
        sobj = cwin.Document;//IE
        alert("ie");
        }
     }
     else{ 
        if(cwin.contentWindow.document){
        sobj = cwin.contentWindow.document;//Opera
	    alert("opera ");
        }
        
     }
   }
    for(i in sobj){
     str+=i+"<br/>";
    } 
    document.write(str);
   
}


另外iframe.Doucment的属性还有
引用
namespaces
lastModified
parentNode
nodeType
fileCreatedDate
onbeforeeditfocus
bgColor
oncontextmenu
onrowexit
embeds
scripts
onactivate
mimeType
alinkColor
onmousemove
onselectstart
oncontrolselect
body
protocol
onkeypress
onrowenter
onmousedown
vlinkColor
URL
onreadystatechange
doctype
onbeforedeactivate
applets
fileModifiedDate
onmouseover
dir
media
defaultCharset
firstChild
plugins
onafterupdate
ondragstart
oncellchange
cookie
documentElement
nextSibling
nameProp
referrer
ondatasetcomplete
onmousewheel
onerrorupdate
onselectionchange
lastChild
ondblclick
onkeyup
location
forms
title
onrowsinserted
previousSibling
compatMode
onmouseup
onkeydown
onrowsdelete
onfocusout
fgColor
ondatasetchanged
onmouseout
parentWindow
nodeName
onpropertychange
onstop
onhelp
linkColor
onbeforeactivate
images
readyState
frames
all
onbeforeupdate
onclick
childNodes
onfocusin
anchors
selection
fileUpdatedDate
domain
security
fileSize
ownerDocument
ondataavailable
styleSheets
nodeValue
attributes
activeElement
implementation
links
URLUnencoded
ondeactivate
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics