dukeTemplar
Programmer
Hi. im currently developing a print function where i create an iframe on the fly and try to print it. It works fine in FF but ie and chrome just wont work! it doesnt print. Does anyone have a clue how to reference the object?
function print(){
// Create an iFrame with the new name.
// Hide the frame (sort of) and attach to the body.
var ifrm = document.createElement("iframe");
ifrm.setAttribute("name", "printFrame");
ifrm.setAttribute("id", "printFrame");
ifrm.setAttribute("src", "");
ifrm.style.width.value = "400px";
ifrm.style.height.value = "400px";
document.body.appendChild(ifrm);
// Get a FRAMES reference to the new frame.
var objFrame = window.frames["printFrame"];
// Get a reference to the DOM in the new frame.
//var objDoc = objFrame.document;
var objDoc =window.frames["printFrame"].document;
// Grab all the style tags and copy to the new document
var headTags = document.getElementsByTagName('head')[0].innerHTML;
//console.log("headTag: "+headTags);
// Write the HTML for the document. In this, we will write out the HTML of the current element.
objDoc.open();
//objDoc.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \" );
objDoc.write( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN \">" );
objDoc.write( "<html>" );
objDoc.write( "<body>" );
objDoc.write( "<head>" );
objDoc.write( "<title>" );
objDoc.write( document.title );
objDoc.write( "</title>" );
objDoc.write( headTags );
objDoc.write( "</head>" );
objDoc.write( content );
objDoc.write( "</body>" );
objDoc.write( "</html>" );
objDoc.close();
// Print the document.
objFrame.focus();
objFrame.print();
}
function print(){
// Create an iFrame with the new name.
// Hide the frame (sort of) and attach to the body.
var ifrm = document.createElement("iframe");
ifrm.setAttribute("name", "printFrame");
ifrm.setAttribute("id", "printFrame");
ifrm.setAttribute("src", "");
ifrm.style.width.value = "400px";
ifrm.style.height.value = "400px";
document.body.appendChild(ifrm);
// Get a FRAMES reference to the new frame.
var objFrame = window.frames["printFrame"];
// Get a reference to the DOM in the new frame.
//var objDoc = objFrame.document;
var objDoc =window.frames["printFrame"].document;
// Grab all the style tags and copy to the new document
var headTags = document.getElementsByTagName('head')[0].innerHTML;
//console.log("headTag: "+headTags);
// Write the HTML for the document. In this, we will write out the HTML of the current element.
objDoc.open();
//objDoc.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \" );
objDoc.write( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN \">" );
objDoc.write( "<html>" );
objDoc.write( "<body>" );
objDoc.write( "<head>" );
objDoc.write( "<title>" );
objDoc.write( document.title );
objDoc.write( "</title>" );
objDoc.write( headTags );
objDoc.write( "</head>" );
objDoc.write( content );
objDoc.write( "</body>" );
objDoc.write( "</html>" );
objDoc.close();
// Print the document.
objFrame.focus();
objFrame.print();
}