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

technologysmiths
technologysmiths used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
F IgorDeveloper

Commented:
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

Author

Commented:
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

Author

Commented:
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!
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

F IgorDeveloper

Commented:
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/

Author

Commented:
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...
Developer
Commented:
Ensure you are using this configuration:

In HEAD include the jquery , jquery-ui and jquery-ui css (also you can download and link it locally )

<head>
<script src="//code.jquery.com/jquery-1.10.1.js" ></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js" ></script>
<link rel=stylesheet href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" >
</head>

Your dialog (there is the place to fix the iframe width )

<div id="dialog"  >
  <iframe style="width:800px;height:600px;border:0px solid gray" src="b.html" >      
  </iframe>
</div>

Open in new window



The javascript code to initialize dialog (in body, no position)

<script>  $(function() {
      
    $( "#dialog" ).dialog({
            autoResize: true,
            width: "auto",
            height: "auto",
            modal: false,
            title: 'Your modal title'
        });
       
  });
</script>

Open in new window


using the options from the example you can get it working.
test.zip

Author

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

Author

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial