2013-04-01 56 views
0

我在div(如popup)中有一个iframe,其高度和宽度可以变化。我尝试以各种可能的方式设置高度和宽度,但未成功。
我无法理解原因。
谁能helpe我out.Here是jsbin将宽度设置为Iframe的父div标签

这里是我猜应该工作的代码:

<!DOCTYPE HTML PUBLIC> 
<html> 
<head> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script> 

<style type="text/css"> 
    #irmNPopupContainer { 
     border: 2px solid; 
     display: none; 
     top: 10px; 
     left: 10px; 
    } 

    #irmNPopupHdr { 
     height: 30px; 
     width: 100%; 
     background: #F0F0F0; 
    } 
</style> 
</head> 

<body> 

    <button onClick="showIrmNPopup('Window Title','http://www.w3schools.com',200,200)">W3 Schools</button> <br/> 

    <div id="irmNPopupContainer" > 
    <div id="irmNPopupHdr"><span></span><span><img src="round_black_close2.png" title="Close">X</span></div> 
    <div id="irmNPopupContent" > 
     <iframe frameborder=0 id="irmNPopupContentFrame" name="irmNPopupContentFrame" scrolling=auto width="100%" height="100%"> 
     </iframe> 
    </div> 
    </div> 
</body> 

    <script> 
    function showIrmNPopup(_title,_src,_width,_height){ 
    //Assign source to iframe and set width and height of the iframe 
    var iframeObj = document.getElementById('irmNPopupContentFrame'); 
    iframeObj.src = _src; 

    $('#irmNPopupHdr span:first-child').text(_title); 
    $('#irmNPopupContainer').show(600); 
    // $('#irmNPopupContainer').outerWidth(_width); 
    //$('#irmNPopupContainer').outerHeight(_height); 
    $('#irmNPopupContainer').css({width:_width+"px",height:_height+"px"}); 
// document.getElementById('irmNPopupContainer').style.width = _width+"px"; 
} 
$('#irmNPopupHdr span:last-child').click(function(){ 
    $('#irmNPopupContainer').hide(600); 
}) 
    </script> 

</html> 
+1

如果我理解你的问题,你必须设置“irmNPopupContent”第一次在IFRAME SRC的。用$('#irmNPopupContainer')开始脚本。css({width:_width +“px”,height:_height +“px”});看看这个:http://jsbin.com/oxemet/4 –

+0

@IvinvinDominin谢谢。 –

+0

评论发布为答案;很高兴帮助你。 –

回答

1

如果我正确理解你的问题,你必须设置“irmNPopupContent”高度和宽度首先设置iframe src。 $('#irmNPopupContainer').css({width:_width+"px",height:_height+"px"});

看这个jsbin: 与启动脚本jsbin.com/oxemet/4

相关问题