【问题标题】:Set width to Iframe's parent div tag将宽度设置为 iframe 的父 div 标签
【发布时间】:2013-04-01 07:18:20
【问题描述】:

我在 div(作为弹出窗口)中有一个 iframe,其高度和宽度可以是可变的。我尝试以所有可能的方式设置高度和宽度,但没有成功。
我无法理解原因。
有人可以帮帮我吗。这是jsbin

这是我认为应该可以工作的代码:

<!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>

【问题讨论】:

  • 如果我理解您的问题,您必须先设置“irmNPopupContent”,然后再设置 iframe src。使用 $('#irmNPopupContainer').css({width:_width+"px",height:_height+"px"}); 启动脚本看看这个:jsbin.com/oxemet/4
  • @IrvinDominin 谢谢。
  • 评论作为答案发布;很高兴为您提供帮助。

标签: javascript jquery css html


【解决方案1】:

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

看看这个jsbin:jsbin.com/oxemet/4

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-27
    • 2013-07-22
    • 2011-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    相关资源
    最近更新 更多