Rama Rao M
Rama Rao M

Reputation: 3051

Set width to Iframe's parent div tag

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

Here is the code that I guess should work:

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

Upvotes: 0

Views: 917

Answers (1)

Irvin Dominin
Irvin Dominin

Reputation: 30993

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"});

Look at this jsbin: jsbin.com/oxemet/4

Upvotes: 1

Related Questions