How to print out sub div on new page using javascript in ASP.NET MVC?

℡╲_俬逩灬. 提交于 2020-06-28 08:06:47

问题


I use the following javascript code to print out orders pages in MVC view :

<script type="text/javascript">

    function PrintElem(elem)
    {
        Popup($(elem).html());
    }

    function Popup(data)
    {
        var mywindow = window.open('', 'divprint', 'height=400,width=600');
        mywindow.document.write('<html><head><title></title>');
        /*optional stylesheet*/ // mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
       // myWindow.document.styleSheets = window.document.styleSheets;
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');

        mywindow.document.close(); // necessary for IE >= 10
        mywindow.focus(); // necessary for IE >= 10

        mywindow.print();
        mywindow.close();

        return true;
    }

The main div id = divprint:

var mywindow = window.open('', 'divprint', 'height=400,width=600');

But i have 6 subdiv under the main div and i need to print each sub div on seperate new page now its comming following on each page , i need if there is space on the page not print next div on same page and go to new page:

<div id="divprint" class="tab-content">

<div id="div1" class="tab-content">
</div>
<div id="div2" class="tab-content">
</div>
<div id="div3" class="tab-content">
</div>
<div id="div4" class="tab-content">
</div>

</div>

I need to print out div1 on first page , print out div2 on second page , print out div3 on third page and so on . How can i do this ?

来源:https://stackoverflow.com/questions/62233448/how-to-print-out-sub-div-on-new-page-using-javascript-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!