0

I'm trying to print the contents of whatever is inside the <div>. I did that successfully, but the contents that need to be printed comes in a popup window.

Is it possible to see the contents that need to be printed in a new tab?

JavaScript code to do the printing:

<script type="text/javascript" >

    function printdiv(printpage) {
        var headstr = "<html><head><title></title></head><body>";
        var footstr = "</body>";
        document.getElementById('<%=lblDateTime.ClientID %>').style.display = "block";
        document.getElementById('<%=lblDateTime.ClientID %>').innerHTML = new Date().toLocaleString();
        var newstr = document.all.item(printpage).innerHTML;
        var oldstr = document.body.innerHTML;
        document.body.innerHTML = headstr + newstr + footstr;
        w = window.open("", "_blank", "k").focus();
        w.document.write(headstr + newstr + footstr);
        w.print();
        document.body.innerHTML = oldstr;
        return false;
    }

</script>

<div id="div_print">
this contenet needs to be printed in a new tab rather than a pop up window
</div>

Any help will be appreciated.

Gass
  • 7,536
  • 3
  • 37
  • 41
rimi
  • 624
  • 5
  • 15

1 Answers1

0

This is code to open a new window with a name of "NewWin" and print some text to it.

var myWindow = window.open("", "NewWin", "width=200,height=100");

myWindow.document.write("<p>This is 'NewWin' hehehehe!!!!</p>");

  • I know how to open a new pop up window using window.open, but I dont how to put the content in new tab rather than new window. – rimi Sep 05 '21 at 18:07
  • [Check this stack-overflow page](https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window) I hope you will find your answer here. – Raushan Kumar Sep 06 '21 at 01:37