Hi:
I have a problem about how to detect the event of afterprint in chrome.
The following is my code snippet:
protected void btnView_Chrome(object sender, EventArgs e)
{
string s = string.Empty;
s += "var doc = oWin.document; doc.write(" + "\"";
s += "<iframe src=" + PDFfilePath + " style='height:0; display: none;' onload=\\\"this.contentWindow.print();\\\"></iframe>\"";
s += ");";
s += "oWin.setTimeout(\"document.getElementsByTagName(\\\"BODY\\\")[0].addEventListener(\\\"afterprint\\\", function(){console.log(\\\"1000\\\");}());\",3000);oNewWin.blur(); this.blur();" + "</script>"; ;
string f = string.Empty;
f = @"<script language='javascript'>
oWin = window.open('','','width=0,height=0,top=0,left=0,toolbar=no,resizable=no,scrollbars=no,status=no');";
f += s;
string strOpenNew = f;
ScriptManager.RegisterStartupScript(this.btnPrint, this.GetType(), "PrintItem", strOpenNew, false);
}The code can run but can't detect the afterprint event in chrome, instead, it will
be execute all instructions at init stage. I also try another methods, like:
s += "oNewWin.setTimeout(\"console.log(\\\"teseting!!!\\\"); console.log(\\\"teseting2!!!\\\");window.onafterprint = function(){console.log(\\\"teseting3!!!\\\");}();\",10000);oNewWin.blur(); this.blur();";But they all fail, the only way can work is following:
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ev_onafterprint
But I don't know how to declare that in doc.write, is there good suggestion for that,
Thanks a lot.