Sol Sol - 8 months ago 23
jQuery Question

How can you load an external web page into an Iframe with Jquery with Custom variables?

Can you load a page into an iframe with JQuery? I have a page that creates a custom printable pdf and need it to load into an iframe to make it easier for the user. I use jquery to pull in all the variables otherwise I could have it load within the page. I am not sure what I am missing with this command to load the page within id="print_form_modal2"?

$("#print_form").prepend('<div id="newDiv"></div>');

<iframe id="print_form_modal2" name="iFrame" src="">


Its simple enough to do what you're trying to do using just JavaScript and HTML

HTML: <iframe id="print_form_modal2" name="iFrame">


function openIframe() {
document.getElementById("print_form_modal2").setAttribute("src", "");


You can see the code in a CodePen here:

In your code you need to replace with the source path for PDF you wish to display, and change when openIframe is called to suit your requirements.