I am working on an asp.net project and on part of it, I needed to print a part of the page which contains an image using javascript. After some digging, I found a code and it works fine.
<script>
function VoucherSourcetoPrint(source) {
return "<html><head><script>function step1(){\n" +
"setTimeout('step2()', 10);}\n" +
"function step2(){window.print();window.close()}" +
"\n</scri" + "pt></head><body onload='step1()'>\n" + <%-- lokk this line--%>
"<img src='" + source + "' style='width: 300px; height: 150px; margine:none;' /></body></html>";
}
function VoucherPrint(source) {
Pagelink = "about:blank";
var pwa = window.open(Pagelink, "_new");
pwa.document.open();
pwa.document.write(VoucherSourcetoPrint(source));
pwa.document.close();
}
</script>
As you can see on the first function it is returning a string and in that there is a script closing tag, which is written as </scri" + "pt>, first I thought it was a mistake and tried removing the extra quotes and plus sign and then the string showing error.
I am confused, why is it have to be like </scri" + "pt>??

<script>tag prematurely.