我有谷歌Chrome的34.0.1847.116版本。我正在使用以下代码进行打印
$('#print').live("click", function(){
var url = baseUrlReports + "******************";
var txnwindow = window.open(url ,"");
txnwindow.print();
txnwindow.focus();
});此时,Chrome挂在加载预览。然后我的所有JS都停止响应,我无法刷新页面。没有其他选项可以关闭窗口。有人能告诉我这里到底有什么问题吗?同样的代码在FireFox和IE上运行良好。
发布于 2014-04-24 23:59:06
好吧,我也有同样的问题
对于那些有兴趣看到它的人--你可以在这里找到并复制它:http://jsfiddle.net/pvkovalev/vGr7Y/ (关闭Chrome中的打印弹出,不要使用“打印”或“关闭”按钮,只需关闭窗口本身)
这是我的解决方案(我基本上没有在Chrome中调用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/
这是到目前为止我能找到的最好的解决办法。
https://stackoverflow.com/questions/23261536
复制相似问题