create html page and print to new tab in javascript

前端 未结 2 1645
醉梦人生
醉梦人生 2020-12-19 17:15

create html page as inline and that page open to new tab and show print view

i tried with this code but not working..

     var mywindow = window.open         


        
相关标签:
2条回答
  • 2020-12-19 17:51

    try this..

    var winPrint = window.open('', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
    winPrint.document.write('<title>Print  Report</title><br /><br /> Hellow World');
    winPrint.document.close();
    winPrint.focus();
    winPrint.print();
    winPrint.close(); 
    

    if the window is not open .. please check whether the popup is blocked :)..

    0 讨论(0)
  • 2020-12-19 18:08

    as you need to open a new tab and then make it print .. try this..

    <div id="toNewWindow">
        <p>Your content here</p>
    </div>
    <a href="javascript:;" id="print">Open</a>
    <script>
    function nWin() {
      var w = window.open();
      var html = $("#toNewWindow").html();
    
        $(w.document.body).html(html);
        w.print();
    }
    
    $(function() {
        $("a#print").click(nWin);
    });</script>
    

    fiddle :: http://jsfiddle.net/Sarathv15/8dXvt/420/

    0 讨论(0)
提交回复
热议问题