Sol Sol - 5 months ago 4
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"?

$.frameReady(function(){
$("#print_form").prepend('<div id="newDiv"></div>');
$('#newDiv').load("print_audit.php?auditID="+auditID+"&action=print&print_name="+print_name+"&print_orient="+print_orient+"&download_option="+download_option+"&type=pdf");
}));



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

Answer

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

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

JavaScript:

function openIframe() {
document.getElementById("print_form_modal2").setAttribute("src", "https://www.example.com/");

}

You can see the code in a CodePen here: http://codepen.io/anon/pen/VjbBbY

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

Comments