首页 > 其他 > 详细

操作iframe

时间:2015-05-03 20:23:38      阅读:226      评论:0      收藏:0      [点我收藏+]

获取子级iframe

contentWindow 所有浏览器都支持的 chrome要服务器环境才可以

contentDocument ie 6 7 不支持

 

document.getElementById(‘iframe_id‘).contentWindow.document.getElementById(‘子页面元素节点‘);

 

window.parent  子frame操作父级页面

window.parent.document.getElementById(‘父页面元素节点‘).style.cssText=..

window.top 获取最顶层一级页面

window.top.document.getElementById(‘最顶层页面元素节点‘).style.cssText=..

 

 

防止被嵌套:

 

if(window!=window.top){

window.top.location.href=window.location.href

}

------------------------------------------------------------------------------------------------------------------

iframe自适应高度和宽度:

function IFrameReSize(iframename) {

  var pTar = document.getElementById(iframename);

  if (pTar) {  //ff

  if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {

  pTar.height = pTar.contentDocument.body.offsetHeight;

  } //ie

  else if (pTar.Document && pTar.Document.body.scrollHeight) {

  pTar.height = pTar.Document.body.scrollHeight;

  }

  }

  }

  //iframe宽度自适应

  function IFrameReSizeWidth(iframename) {

  var pTar = document.getElementById(iframename);

  if (pTar) {  //ff

  if (pTar.contentDocument && pTar.contentDocument.body.offsetWidth) {

  pTar.width = pTar.contentDocument.body.offsetWidth;

  }  //ie

  else if (pTar.Document && pTar.Document.body.scrollWidth) {

  pTar.width = pTar.Document.body.scrollWidth;

  }

  }

  }

  使用方法如下:

  <iframe src="Main.aspx" scrolling="no" frameborder="0" height="100%" id="mainFrame" width="100%" onload=‘IFrameReSize("mainFrame");IFrameReSizeWidth("mainFrame");‘></iframe>

操作iframe

原文:http://www.cnblogs.com/leyi/p/4474528.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!