Avatar of technologysmiths
technologysmiths
 asked on

How to load local html / PHP content into an iframe using modal popup? (html5, javascript and/or CSS) ?

I need to load a formatted html file (b.html) within a modal popup which is launched from a local html file (a.html)

The content of b.html is formatted to 800px x 600px and I would like to be able to display this content within the modal popup without any scroll bars showing.

I would also like to be able to close the modal by clicking an 'X' on the top right of the modal box and no where else on the modal or background...

Please can you provide any help and ideally detailed examples or instructions on how I can go about doing this using modern methods, if possible.

Many Thanks
HTMLJavaScriptjQueryJScriptWeb Development

Avatar of undefined
Last Comment
technologysmiths

8/22/2022 - Mon
Francisco Igor

Using jquery/jquery ui api  (See https://jqueryui.com/dialog/#default)
Using an iframe inside dialog container:


<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#dialog" ).dialog();
  });
  </script>
</head>
<body>
 
<div id="dialog" title="Basic dialog">
  <iframe src="b.html" style="width:800px;height:600px;border:0px;" ></iframe>
</div>
 
 
</body>
</html>

Open in new window

technologysmiths

ASKER
Thank you fraigor - do you know how I can remove the scroll bars and resize the pop up? Please see a screen shot below:

Image of popup
technologysmiths

ASKER
Hi,

As a quick update I found how to remove the scroll bars from the inner (iframe?) page.
 
I added the below to the b.html page which is loaded within the pop up:

<style type="text/css">
body {
    overflow:hidden;
}
</style>

Open in new window



I tried doing the same on the a.html (parent) page but I can't remove the horizontal scroll bar and the popup window also remains a fixed small width no matter what pixel number I set in the section below (it does however respond to the height setting!):

style="width:800px;height:600px;border:0px;

Open in new window



Any pointers you can give will be much appreciated, thank you for your help!
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Francisco Igor

Try using the dialog options like this example (autoresize, automatic width/height)
And only setting initial iframe width/height

$(function() {
    $( "#dialog" ).dialog({
            autoResize: true,
            width: "auto",
            height: "auto",
            modal: false,
            title: 'Modal title',
            position: ['top', 'center']
        });
  });

Open in new window


See an example https://jsfiddle.net/03tn85nm/2/
technologysmiths

ASKER
Thanks, I have been trying to crack this for hours and cant seem to see how to over-ride the default width settings of 300px regardless of what is set locally. I tried touse  examples  from the link above with no success...

Should I download the jQuery UI libs locally and manually edit the script/component that is controlling this and then point my pages to the local version?

Many thanks, this has been driving me crazy...

Everything but width can be and is set as needed...
ASKER CERTIFIED SOLUTION
Francisco Igor

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
technologysmiths

ASKER
Thank you sir - this is much appreciated - I had found a solution which got me 95% of the way there and the info you provided has taken me to a full 100% - thank you!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
technologysmiths

ASKER
fraigor went above and beyond to help me - many thanks!