Scenario:
I create a new window (new tab) and write html markup to it via javascript. 1. a new document. 2. Record the html markup for the contents of the document. 3. show a new document.
What I need to do:
I need to print a simple HTML page (javascript print dialog) by clicking on a button, link or download. The problem is that I cannot work in any way ... with one exception.
(the only exception) Using onload = "window.print ()" will only work if a new window appears and I click refresh (the print dialog will not be displayed when the window is initially created).
Strange, even if I call "window.print ()" on event clicks (href, button ... etc.) nothing happens. But I know that this is not a browser, because the samples / demos of this SIMPLE thing work fine.
So it seems that this is somehow connected with the fact that my page is displayed as it is (described in the "Script" section).
CODE:
When I click the Print button, I call this (right now it doesn't matter exactly who / what calls this, but just know that it is being called):
function Print(htmlContent) {
var printWindow = window.open();
var printDoc = printWindow.document;
printDoc.write(htmlContent);
And I forgot to mention this: HTML (htmlContent), which is passed to the Print scrip function, is really Html, but it has been converted by XSL. Here is the XSL:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<style type="text/css" media="print">
.noprint{
display:none;
}
</style>
<script type='text/javascript'>
function startPrint(){
window.print();
}
</script>
</head>
<body>
<div >
<a id="printButton" href="startPrint();">Print this page</a>
</div>
Hello world.
</body>
</html>
</xsl:template>
</xsl:stylesheet>
javascript, , href= "startPrint()" href= "alert ('hi')", .