TTS Framework - JavaScript assets.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
tts_js/core/addons/print_frame.js

41 lines
1.4 KiB

/**
* Printer Support
* @author Robert Strutts <Robert@TryingToScale.com>
* @copyright Copyright (c) 2019, Robert Strutts.
* @license https://mit-license.org/
*/
/* Printer Framed Window */
var array_of_frames = []; /* Needed to track open iFrames */
var printFrameID = 0;
function donePrintFrame() {
var frm = document.getElementById(printFrameID).contentWindow;
frm.focus();
frm.print(); /* set focus on contentWindow is needed on some ie versions */
}
/* id is the id of the iframe */
tts.printFrame = function (id, src) {
try {
for (var i = 0; i < array_of_frames.length; i++) {
document.body.removeChild(array_of_frames[i]); /* Delete old page when done, for new data */
array_of_frames.pop();
}
var newIframe = document.createElement('iframe');
newIframe.width = '0';
newIframe.height = '0';
newIframe.name = id;
newIframe.id = id;
newIframe.src = src;
printFrameID = id;
document.body.appendChild(newIframe);
array_of_frames.push(newIframe); /* Add frame to list to be removed next time */
newIframe.onload = donePrintFrame;
} catch (err) {
tts.logger(err.message);
}
return false;
};
/*
* End of Printer Support
*/