iFrame.offsetWidth is not working expectedly.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    iFrame.offsetWidth is not working expectedly.

    Here is my HTML code ..

    Code:
    <iframe src="reference_page.html" id="test_fr"></iframe>
    Have a look at my reference HTML code

    Code:
    <body>
    <div style="height:700px;width:800px">
    </div>
    </body>
    Now my Java Script code ..

    Code:
    var iFrame = document.getElementById('test_fr');
    alert(iFrame.contentDocument.body.offsetWidth+'\t'+iFrame.contentDocument.body.offsetHeight);
    Now my JS code gives me offsetHeight properly..means 700.
    But offsetWidth is not ..
    What's the cause ?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by dmjpro
    But offsetWidth is not ..
    what does it give and what do you expect?

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by Dormilich
      what does it give and what do you expect?
      It gives a value which is not 800 as offsetHeight given ... ;)

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        so, what does it give instead (I may draw a conclusion from that…)?

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by Dormilich
          so, what does it give instead (I may draw a conclusion from that…)?
          267 in firefox 2.
          How does it help to draw a conclusion .. ?

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Well, I able to configure the solution, not the reason.
            Still waiting for the reason ;)
            Now i am calculating the width of a Body ....

            Code:
            var iFrame = document.getElementById('frame_id');
            	//alert(iFrame.contentDocument.body.firstChild.offsetWidth);
            	var maxWidth = 0;
            	var children = iFrame.contentDocument.body.childNodes;
            	alert(children.length);
            	for(var i=0;i<children.length;i++){
            		if(children[i].offsetWidth && children[i].offsetWidth>maxWidth) maxWidth = children[i].offsetWidth;
            	}
            	alert(maxWidth);

            Comment

            Working...