2013-05-31 41 views
0

我创建了一个iframe,当我单击某些链接时会加载多个图像。 iframe可以在Chrome和Firefox中正常工作,但使用IE会将图像向下和向右放下约15px,创建一个白色背景。IE中的iframe将内容向下并向右移动

iframe与我加载的图像大小完全相同(880 x 980)。 我不想在iframe中“推动”图像,只是在工作的浏览器中设置它。

这可能是一些简单的我不注意..任何想法?

iframe { 
margin: 0; padding: 0; 
position: absolute; top: 0; left: 0 auto; 
_height: 980px; 
_width: 880px; 


<iframe width="880" height="980" id="display" name="display" scrolling="no" frameBorder="0" allowTransparency="true" src="display.html"><center></center></iframe> 
+0

为什么你使用iframe是什么?只需在其中放置''元素,然后通过JS更改其'src'属性以加载新图像... – CBroe

+0

对不起,我不擅长编码。无论如何,你可以举一个适当的例子吗?我将不胜感激! – SaturnsEye

回答

0

试试这个

JAVASCRIPT

function autoResize(id){ 
     var newheight; 
     var newwidth; 

     if(document.getElementById){ 
      newheight=document.getElementById(id).contentWindow.document .body.scrollHeight; 
      newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth; 
     } 

     document.getElementById(id).height= (newheight) + "px"; 
     document.getElementById(id).width= (newwidth) + "px"; 
    } 

HTML

<iframe width="880" height="980" id="iframe1" name="display" scrolling="no" frameBorder="0" allowTransparency="true" src="display.html" onLoad="autoResize('iframe1');"><center></center></iframe>