Incorporating a responsive iframe into a jQuery modal dialog box

Attempting to integrate a responsive iframe within a dialog box has been quite the challenge. My initial approach, as seen in Fiddle 1, involved displaying an iframe upon button click, but unfortunately, it lacked responsiveness and failed to resize with the page.

I turned to the insights provided here, where I utilized CSS container styling to achieve responsive behavior for the iframe. By assigning a class to the iframe and setting the height to 120%, the display was clipped at the bottom as desired. You can view the updated version in Fiddle 2

Now, my aim is to transition this modified code into a jQuery dialog box. While the content remains responsive within the dialog, it appears that the iframe class is not being applied properly, resulting in the visible footer of the iframe display. This issue can be observed in Fiddle 3

The ultimate goal is to have the dialog box mirror the responsiveness seen in Fiddle 2 without displaying the iframe footer. Any suggestions or solutions would be greatly appreciated!

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css>
<title>iframe</title>
  <script src="//code.jquery.com/jquery-1.12.4.js></script>
  <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js></script>
</head>
<body>

<button type="button" id="btn1>Button 1</button>

<div id="iFrameDiv" class="iframe-container">
    <iframe style="display:none;" id="myframe1" src="https://app.powerbi.com/view?r=eyJrIjoiMjJlYTYwODktYjU2NS00ZjZiLTg1YTktNDRlZjgzNzFmN2U5IiwidCI6ImRjOWNhZGMxLTJhZTItNGM0YS04MzIwLThlOTViMDAzNGI5NiJ9"  ></iframe>
</div>

</body>
</html>

$( "#myframe1" ).dialog({ 
autoOpen: false, 
resizable: true

});
$( "#btn1" ).click(function() {
  $( "#myframe1" ).dialog( "open" );
});

.iframe-container {
  overflow: hidden;
  padding-top: 56.25%;
  position: relative;
}

.iframe-container iframe {
   border: 0;
   height: 120%;
   left: 0;
   position: absolute;
   top: 0%;
   width: 100%;
}

Answer №1

When a dialog box is created using jQuery UI, it creates a separate section in the DOM for the dialog content. This means that any selectors targeting the parent element will not apply.

Take a look at this Fiddle: http://jsfiddle.net/0h6a3epo/1/

I now use the parent as the dialog element to apply the CSS styles.

In addition, I have included another line of jQuery code to display the iframe because jQuery UI initially applies display:none; by default.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Update and republish an outdated npm package

After successfully publishing an npm package, I attempted to make an update which unfortunately resulted in some issues. It seems that I made a mistake during the build process. Since it had been a year since my last update, I have forgotten the exact step ...

I am in the process of transforming my basic JS Array into one that contains key/value

Currently, I am utilizing jQuery to create an Array in the following manner: var arr = new Array(); $('#some-form .some-input').each(function() { arr.push($(this).val()); ...

Personalized Facebook Share Dialog - unique title and description

I need to send a link using the FB Send Dialog with custom name and description. FB.ui({ method: 'send', name: 'Custom name', display: 'popup', link: 'http://link.com', to: facebookUserId, description: 'Custom ...

Make sure to keep "display:inline-block" in place while using fadeTo()

As a design student, I am working on creating a family tree website where users can click on individual circles (ancestors) to view their lineage. Everything has been functioning smoothly so far, except for when attempting to display the lineage of specifi ...

What is the best way to insert a value into the span element generated by the Tag-it plugin?

Currently working with the Tag-it plugin to generate tags. Since the tags are created using spans, I'm curious to learn how I can assign a value to a tag created by the plugin? Seeking assistance from someone knowledgeable in this area. Thank you! ...

Issue with hiding elements in Bootstrap 4 Beta using display none

Currently experimenting with Bootstrap 4 beta through the CDN, I have encountered a peculiar issue with the newly introduced d-* class. Upon trying out a simple div with the class "d-none d-lg-block", it performed as expected, being visible only when the ...

Adding color to characters, digits in an HTML file

Is it possible to individually style each letter, number, and symbol in an HTML document with a unique color? I am interested in creating a text editor that applies specific colors to each glyph for those who have grapheme-color synesthesia. While there ar ...

What is the proper syntax for using .focus() with the nextElementSibling method in typing?

As I strive to programmatically shift focus in my form using nextElementSibling, I encounter a challenge with typing variables/constants due to working with Typescript... I have managed to achieve success without typing by implementing the following: myF ...

What methods can be used to prevent polygon edge stitching artifacts from occurring on an HTML5 Canvas?

As I manage both parallel Flash and HTML5/Canvas renderers for the OpenHeatMap open-source project, I am encountering an inconsistency in the rendering of filled polygons with fractional coordinates between the two versions. A visible join appears along sh ...

Inserting blocks of text into a MySQL database

I'm hoping to insert text segments into a MySQL database. Below is an excerpt of my HTML code: <div class="margins3"> <h1>Meal Plan...</h1> <div id='results-container'> <div class='LeanMuscle ...

Preserve the Value of jQuery Slider During Postback

I am currently utilizing a jQuery UI slider with great success, the only issue I am facing is related to an ASP.NET hidden field that stores the user's selection on the slider. This hidden field is essential for me to access the value after performing ...

Learn the process of marking an option as selected within an Angular component

I have an Angular component that displays a question along with a dropdown menu (<select>) to choose from various answers. My goal is to programmatically set one of the options as selected based on certain parameters present in the application' ...

Setting specific variables in an array with corresponding key-value pairs

I need help with extracting specific columns from a table that has 5 columns. The columns in question are: column1, user_id, column3, column4, and user_exp. Let's say I have the following select query: $mat_sql = mysql_query( "SELECT * FROM users ...

Is it possible to retrieve stored colors from the Back End and incorporate them into an SCSS file?

Currently, I am in the process of restructuring my code to make it more clear and easier to maintain. I have a concept in mind, but I am struggling with how to implement it effectively. To enhance cleanliness and efficiency, I plan to create a separate _co ...

Issue with EJS template displaying no information

I am encountering an issue with ejs templates. While I have successfully used it in a previous project, in my current one, it's not working as intended. Instead of rendering the cards with the passed data, all I see is a blank page. Here is my code fo ...

Learn how to incorporate a consistent header and footer across multiple pages on a website with Node.js, ExpressJS, and either hbs or ejs templates

Creating a common header (navbar) and footer page to be included in multiple/several pages of a website. I want to create a dynamic website using Node.js and Express.js. The code for the navbar and footer will be placed in a common file named header.html ...

Using TypeScript with React Bootstrap's <Col> component and setting the align attribute to 'center' can trigger a TS2322 warning

The React app I'm working on includes the code below. The Col component is imported from React-bootstrap <Col md={5} align="center"> This is a column </Col> When using Typescript, I received the following warning: ...

Retrieve data from HTML Form arrays using JavaScript

I have a situation in my forms where arrays are being sent back in the following format: <input class="checkbox-service" name="services['electricity']" type="checkbox"> <input class="checkbox-service" name="services['water'] ...

Trigger CSS3 animation only once upon the page loading

I'm in the process of creating a stylish landing page using CSS3. One element that really stands out is an <a> tag with a cool animation: @keyframes splash { from { opacity: 0; transform: scale(0, 0); } 50% { ...

Setting the UrlAction in an Asp.Net Core Controller: A step-by-step guide

There is an input box for searching on the website... The following HTML code snippet shows how the search functionality is implemented: <form id="searchForm" asp-controller="Product" asp-action="SearchProduct" method=&quo ...