좋아, 그래서 저도 같은 문제를보고 관심이 분들을 위해
있어 버튼 "인쇄"또는 "닫기"를 사용하지 마십시오, 그냥 윈도우 자체) 그래서 여기
내 솔루션입니다 크롬 (나는 기본적으로 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/
내가 지금까지 찾을 수 있었던 가장 좋은 해결 방법입니다.
같은 문제가 발생하는 경우 :/ –
어쩌면 발생률은 없지만 jQuery 라이브 메소드는 사용되지 않습니다. https://api.jquery.com/live/ 대신 .on() 메소드를 사용해야합니다. – labilbe