iframes have a limitation in automatically adjusting to fit the size of their target content. Essentially, there isn't an "auto" value for the width or height of an iframe, you must specify the dimensions of the frame.
To address this issue, you need to determine the size of the content beforehand so that you can pass it to your iframe along with the designated URL. One way to achieve this is by using data attributes.
Instead of specifying the width and height directly in the iframe tag, you can set them dynamically based on the selected URL from a dropdown menu using the following HTML and JavaScript/jQuery code:
<select id="frameURL">
<option value="http://www.url1.com/" data-cheight="600">URL 1</option>
<option value="http://www.url2.com/" data-cheight="750">URL 2</option>
<option value="http://www.url3.com/" data-cheight="1200">URL 3</option>
</select>
<iframe scrolling="no" style="display:none;" id="myFrame" src=""></iframe>
$("#frameURL").change(function(){
// Get the selected URL
var target = $(this).find("option:selected").val();
// Default fixed width of content area
var cntWidth = 500;
// Get content height from data-cheight attribute
var cntHeight = $(this).find("option:selected").attr("data-cheight");
// Pass all attributes to the iframe
$("#myFrame").attr({
src: target,
width: cntWidth,
height: cntHeight
});
// Hide iframe when src attribute is empty (no URL chosen)
!$("#myFrame").attr("src") ? $("#myFrame").hide() : $("#myFrame").show();
});
Check out the working model: https://jsfiddle.net/xxgs901u/3/