Click here to Skip to main content
14,386,540 members
Rate this:
Please Sign up or sign in to vote.
See more:
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

thanks
Posted
Updated 4-Nov-19 13:23pm
v2
Comments
Christian Graus 6-Jul-11 0:21am
   
Are you asking/looking for width, or height ?
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can get client height in JavaScript by

//Width
document.body.clientWidth

//Height
document.body.clientHeight
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

hi,
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[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100