I get ‘parent.iframePDF is undefined’ JavaScript error when i use the below code in Firefox and an ‘object expected’ error in IE.
Can someone tell me what it is that i’m doing wrong? Thanks
function PrintFrame(xFile){
parent.iframePDF.location.href = xFile;
document.getElementById("spanMess").style.display = "block";
parent.iframePDF.onload = new function() {
setTimeout("parent.iframePDF.print();parent.document.getElementById('spanMess').style.display='none';",10000);
}
}
<iframe id="iframePDF" src="about:blank" style="display:none"></iframe>
<input type="image" onclick="PrintFrame('525.pdf')" src="../../cms_res/DisneyChannel/playhouse/images/buttons/printer.png" />
<span id="spanMess" style="display:none;color:red;">
<h3>Preparing Document For Print</h3>
</span>
You should use name=”iframePDF” instead of id=”iframePDF”.
In that way, you can use window.iframePDF (-> window.frames.iframePDF).
If you use document.getElementById(‘iframePDF’), then you can’t use .location.href on that.
Edit: Tim is right, no parent is needed here.