iframe中的客户端高度 [英] client height in iframe

查看:116
本文介绍了iframe中的客户端高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想根据客户端页面宽度调整iframe的大小.我正在使用以下脚本,但这是否使我获得0高度的想法,如何获得客户端宽度.

Hi,

I want to resize the iframe according to the client page width.i am using the following script for this but is it giving me 0 height any idea how can the client width can be get.

parent.document.getElementById(''iframename'').height =
parent.document.getElementById(''iframename'').contentWindow.document.body.scrollHeight


谢谢

推荐答案

您可以通过
在JavaScript中获取客户端高度
You can get client height in JavaScript by

//Width
document.body.clientWidth

//Height
document.body.clientHeight



请在下面尝试此代码

try this code below
var  myHeight  = (typeof(window.innerHeight)!='undefined'?window.innerHeight:document.body.offsetHeight);




or

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}


函数引用取自此处 [


function reference taken from here[^]


这篇关于iframe中的客户端高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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