2017-12-04 15 views

답변

0

screenshot

는보기 모바일에이 코드

$(function() { 
 
    $("#btnPrint").click(function() { 
 
    var contents = $("#dvContents").html(); 
 
    var frame1 = $('<iframe />'); 
 
    frame1[0].name = "frame1"; 
 
    frame1.css({ "position": "absolute", "top": "-1000000px" }); 
 
    $("body").append(frame1); 
 
    var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument; 
 
    frameDoc.document.open(); 
 
    //Create a new HTML document. 
 
    frameDoc.document.write('<html><head><title>DIV Contents</title>'); 
 
    frameDoc.document.write('</head><body>'); 
 
    //Append the external CSS file. 
 
    frameDoc.document.write('<link href="style.css" rel="stylesheet" type="text/css" />'); 
 
    //Append the DIV contents. 
 
    frameDoc.document.write(contents); 
 
    frameDoc.document.write('</body></html>'); 
 
    frameDoc.document.close(); 
 
    setTimeout(function() { 
 
     window.frames["frame1"].focus(); 
 
     window.frames["frame1"].print(); 
 
     frame1.remove(); 
 
    }, 500); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="dvContents"> 
 
    <div class="clear"></div> 
 
    <hr /> 
 
    <div class="contents"> 
 
    <span class="label">Hello, 
 
     <br /> 
 
     This is <span class="name">Karan Mehta</span>.<br /> 
 
     Hoping that you are enjoying This! 
 
    </span> 
 
    </div> 
 
</div> 
 
<br /> 
 
<input type="button" id="btnPrint" value="Print" />

+0

이 방법은 웹용으로 완벽하게 작동합니다. 나는 모바일보기를 찾고있다. 그것을 할 수있는 다른 방법이 있습니까? – user3143998