2014-04-24 4 views
1

버전이 34.0.1847.116 인 Google 크롬이 있습니다. 나는이 순간Chrome에서 인쇄 문제가 발생했습니다.

$('#print').live("click", function(){ 
var url = baseUrlReports + "******************"; 

var txnwindow = window.open(url ,""); 
txnwindow.print(); 

txnwindow.focus(); 

}); 

을 인쇄하기 위해 다음 코드를 사용하고있는 크롬은로드 미리보기에서 멈 춥니 다. 그러면 모든 JS가 응답을 멈추고 페이지를 새로 고칠 수 없습니다. 창을 닫을 다른 옵션이 없습니다. 아무도 정확하게 여기에 문제가 무엇인지 말해 줄 수 있습니까? 동일한 코드가 FireFox 및 IE에서 잘 작동합니다. , http://jsfiddle.net/pvkovalev/vGr7Y/가 (단지 크롬에서 인쇄 팝업을 닫습니다 찾아서 여기를 재현 할 수 있습니다 -

+0

같은 문제가 발생하는 경우 :/ –

+0

어쩌면 발생률은 없지만 jQuery 라이브 메소드는 사용되지 않습니다. https://api.jquery.com/live/ 대신 .on() 메소드를 사용해야합니다. – labilbe

답변

0

좋아, 그래서 저도 같은 문제를보고 관심이 분들을 위해

있어 버튼 "인쇄"또는 "닫기"를 사용하지 마십시오, 그냥 윈도우 자체) 그래서 여기

내 솔루션입니다 크롬 (나는 기본적으로 window.print를 (전화 아니에요))

//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 </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/

내가 지금까지 찾을 수 있었던 가장 좋은 해결 방법입니다.

+0

모든 브라우저에서 인쇄하고 싶습니다. 크롬이 인쇄되지 않으면 어떻게 해결할 수 있습니까? –

+0

Sir이 Chrome 문제를 해결하는 방법을 모르겠지만 더 나은 해결책을 찾으면 알려 주시기 바랍니다. 이 문제와 관련하여 많은 사용자가 있습니다 ... –