2013-11-22 4 views
0

내 웹 페이지의 특정 div를 인쇄하려면 Jquery 플러그인을 사용하고 있습니다. 그것은 Firfox와 IE에서 잘 작동합니다. 하지만 안타깝게도 Chrome에서 작동하지 않습니다. 실제로 Google 크롬은 배너, 메뉴 및 버튼을 포함한 전체 웹 페이지를 인쇄합니다. 이 문제를 해결할 수 없습니다. 여기 Google 크롬 인쇄 문제

내 샘플 코드입니다

자바 스크립트

$(function() { 
    $("input:button").click(function() { 
     $("#print").printThis(); 
    }); 
}); 

HTML

<body> 
<input type="button" value="print" /> 
<div id="print"> 
this is print area, it can be everything. this is print area, it can be everything. this is print area, it can be everything. this is print area, it can be everything. this is 
</div> 
</body> 
당신은 동일한 기능을 수행하는 "순수"jQuery를 사용할 수 있습니다
+0

사용중인 플러그인을 확인하는 데 도움이됩니다. 어쨌든 대부분의 경우 CSS를 사용하여 전체 페이지를 인쇄하는 것 외에 별도의 인쇄 섹션을 제공하지 않는 한 인쇄 가능한 영역을 정의하는 것이 가장 쉽습니다. – JJJ

답변

0

:

//Begin browser detection section 
var isOpera = !! window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; 
// Opera 8.0+ (UA detection to detect Blink/v8-powered Opera) 
var isFirefox = typeof InstallTrigger !== 'undefined'; // Firefox 1.0+ 
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; 
// At least Safari 3+: "[object HTMLElementConstructor]" 
var isChrome = !! window.chrome && !isOpera; // Chrome 1+ 
var isIE = false || !! document.documentMode; // At least IE6 
    //End browser detection section 

    //User click on something 
$('a[href="#print"]').on("click", function() { 
    var data = "<div> a lot of HTML code from AJAX call or from your DIV </div>"; 
      CreateWindow(data); 
}); 


function CreateWindow(data) { 
    var mywindow = window.open('about:blank', '_blank'); 
    var myWindowContents = '<html>' + 
     '<head>' + 
     '<title>Results</title>' + 
     '<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" type="text/css">' + 
     '</head>' + 
     '<body >' + data + 
     '<script src="http://code.jquery.com/jquery-2.1.0.min.js type="text/javascript">' + '<' + '/script>' + 
     '<script type="text/javascript">' + 
     '$(document).ready(function() {' + 
     '});' + 
     '<' + '/script>' + 
     '</body>' + 
     '</html>'; 
    mywindow.document.write(myWindowContents); 
    mywindow.document.close(); 
    mywindow.focus(); 
    if (!isChrome) { 
     mywindow.print(); 
    } 
} 
나는 그것이 당신에게 당신의 문제를 해결하는 방법 아이디어를 줄 것이다 생각 http://jsfiddle.net/pvkovalev/2pn4p/ : 6,

또한 여기내 코드를 볼 수 있습니다.