Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: Element Offsets Are "-1" When IFRAME Is Hidden


View products that this article applies to.

This article was previously published under Q256977

↑ Back to the top


Symptoms

When you place relatively-positioned elements inside a page that is set as the source of an IFRAME, the offsetLeft and offsetTop properties of elements on that page return "-1" when you set the style of the IFRAME to "display:none". This is a change from Internet Explorer 5, in which the offset* properties of the element return the true offset value regardless of the IFRAME's display state.

↑ Back to the top


Cause

Internet Explorer 5.5 introduced the concept of "native frames", which include the conversion of IFRAMEs from windowed controls to windowless native elements. When IFRAME was windowed, the only way you could implement "display:none" was to create the IFRAME and move it off the visible area of the page. This rendered and positioned all child content before you moved the IFRAME off-screen.

However, because IFRAMEs are windowless in Internet Explorer 5.5, you can position neither the IFRAME nor its containing elements until you make the IFRAME visible.

↑ Back to the top


Resolution

Because you cannot restore the behavior as it was in Internet Explorer 5, you should revise your pages to use offsetLeft and offsetTop of the contained element's style object.

You can also wrap the contained elements in the IFRAME inside of another element that uses style that is set to "position:relative". This causes the offset* properties to return "0," as they should in this context, instead of -1.

↑ Back to the top


More information

Steps to Reproduce Behavior

  1. Save the following HTML file as TestIFrame.htm:
    <HTML>
    
    <BODY>
    
    <IFRAME id="frm1" style="display:none;" src="TestIFrameContained.htm">
    </IFRAME>
    
    </BODY>
    
    </HTML>
    					
  2. Save the following HTML file as TestIFrameContained.htm:
    <HTML>
    
    <SCRIPT>
    
    function load() {
    	window.alert("Offset left is " + div1.offsetLeft);
    }
    </SCRIPT>
    
    <BODY onload="load();">
    
    <DIV id="div1" style="position:relative;left=40;top=40">
    Hello, world!
    </DIV>
    
    </BODY>
    
    </HTML>
    					
  3. Run TestIFrame.htm inside of Internet Explorer 5 or 5.01 and again in 5.5. In Internet Explorer 5 and 5.01, notice that the offset left of div1 in TestIFrameContained.htm reports "50"; in Internet Explorer 5.5, it reports "-1."
  4. To make the offsetLeft report "0," surround div1 in TestIFrameContained.htm with another DIV set to relative positioning:
    <DIV id="parentDiv1" style="position:relative;">
    <DIV id="div1" style="position:relative;left=40;top=40">
    Hello, world!
    </DIV>
    </DIV>
    					

↑ Back to the top


References

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

↑ Back to the top


Keywords: KB256977, kbprb, kbdhtml

↑ Back to the top

Article Info
Article ID : 256977
Revision : 5
Created on : 5/11/2006
Published on : 5/11/2006
Exists online : False
Views : 332