I am using the below script to format a special print window from my sharepoint site.
The problem is sometimes the very last statement in the script (the picture append) does not load. Is there a way to catch if it fails and force the script to reload ?
I have tried loading the picture directly in the printing html but it seems to not work.
I am not very experienced with javascript, any suggestions of improvement are very welcome
<center>
<input onclick="PrintWebPart();" type="button" value="Print Proof of Pricing"/>
</center>
<script language="JavaScript">
//Controls which Web Part or zone to print
var WebPartElementID = "ctl00_ctl34_g_db6615a7_4c3b_4a14_9bbc_43ce9d63c24d_FormControl0";
var d= new Date();
//Function to print Web Part
function PrintWebPart() {
var bolWebPartFound = false;
if (document.getElementById != null) {
//Create html to print in new window
var PrintingHTML = '<HTML>\n<HEAD>\n';
//Take data from Head Tag
if (document.getElementsByTagName != null) {
var HeadData= document.getElementsByTagName("HEAD");
if (HeadData.length > 0) {
PrintingHTML += HeadData[0].innerHTML;
}
}
PrintingHTML += '\n</HEAD>\n<BODY>\n';
var WebPartData = document.getElementById(WebPartElementID);
if (WebPartData != null) {
PrintingHTML +='<div id="imageDiv" align="center">\n</div>\n'
PrintingHTML += WebPartData.innerHTML;
PrintingHTML += "Pricing Date: " +d;
bolWebPartFound = true;
} else {
bolWebPartFound = false;
alert ('Cannot Find Web Part');
}
}
PrintingHTML += '\n</BODY>\n</HTML>';
//Open new window to print
if (bolWebPartFound) {
var PrintingWindow = window.open("","Print_Proof_of_Pricing", "toolbar= yes,width=800,height=600,scrollbars,resizable,menubar");
PrintingWindow.document.open();
PrintingWindow.document.write(PrintingHTML);
PrintingWindow.document.getElementById('imageDiv').innerHTML = '<img src="Some_url" alt="Title" height="170" width="300"/>';
}
}
</script>