Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend div outside bounds of iFrame?

Is it possible to extend content beyond the bounds of an iframe?

In my case, I was formerly rendering a native <select> control inside of an iframe. As a native control, when it rendered, the dropdown was able to occupy space outside of the iframe. I recently converted the dropdown to use select2, which rebuilds the dropdown using various <span> elements.

The problem is now it gets cutoff within the <iframe>:

Demo

I've tried setting the overflow to visible, but that doesn't work:

iframe {
   overflow: visible
}

Here's a Test Case on Plunker

JavaScript:

$("#OpenSelect2").click(function(){
 OpenPagePopup("select2.html", "Select 2", 150, 400);
});

//Open Diagnosis Control for editting
function OpenPagePopup(location, title, ht, wt) {
  $('<div>')
      .append($('<iframe/>', {
          'class': "fullFrame",
          'src': location
      }))
      .dialog({
          autoOpen: true,
          modal: true,
          height: ht,
          width: wt,
          title: title
      });
}

index.html:

<button id="OpenSelect2">Open Modal with Select2</button>

select2.html:

<select class="select2">
    <option value="AZ">Arizona</option>
    <option value="CO">Colorado</option>
    <option value="ID">Idaho</option>
    <option value="MT">Montana</option>
    <option value="NE">Nebraska</option>
    <option value="NM">New Mexico</option>
    <option value="ND">North Dakota</option>
    <option value="UT">Utah</option>
    <option value="WY">Wyoming</option>
</select>

<script >
  $('.select2').select2();
</script>

Possible Workaround:

DON'T USE IFRAMES! Yeah, I know, I know, but this is the situation I find myself maintaining.

like image 234
KyleMit Avatar asked Jun 26 '15 20:06

KyleMit


People also ask

Can you put a div inside an iframe?

Approach 1: For adding additional div's in an iframe, you need to use a wrapper div, that wraps the contents of your intended div and the iframe into one unit. This way you can display the contents of your div along with the iframe embedding to the document/webpage.

How do I resize an iframe based on content?

Answer: Use the contentWindow Property You can use the JavaScript contentWindow property to make an iFrame automatically adjust its height according to the contents inside it, so that no vertical scrollbar will appear.

How do you change the width and height of a frame in HTML?

<iframe src="" width="" height=""> The width and height attributes of the IFRAME element specifies the width and height of the iframe. This can be specified with CSS.


1 Answers

No. There is no way to extend content outside of an iframe. Think of it as another browser window entirely.

The reason that the options will extend below the iframe is that form elements follow their own rules. They differ from browser to browser, and for some of the elements you can't change the styling. When you use select2 it turns the form into a regular element (not a default form element), so you can manipulate the style. Unfortunately, this also makes it confine to the iframe.

Consider that a browser can also do this (but it doesn't mean you can):

Example

like image 90
tylerism Avatar answered Sep 19 '22 06:09

tylerism