将宽度设置为Iframe的父div标记 [英] Set width to Iframe's parent div tag

查看:172
本文介绍了将宽度设置为Iframe的父div标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iframe在一个div(作为弹出),其高度和宽度可以是可变的。我试图设置所有可能的方式的高度和宽度,但我没有成功。

我无法理解原因。
有人可以帮我。这是一个 jsbin

I have an iframe within a div(as popup) whose height and width can be variable.I tried to set the height and width in all possible ways but I was not succeeded.
I am unable to understand the reason.
Can somebody helpe me out.Here is a 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});

If I understand your problem correctly, you have to set the "irmNPopupContent" height and width first of setting the iframe src. Start your script with: $('#irmNPopupContainer').css({width:_width+"px",height:_height+"px"});

查看此jsbin: jsbin.com/ oxemet / 4

这篇关于将宽度设置为Iframe的父div标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆