gpt4 book ai didi

javascript - Chrome 中的打印问题

转载 作者:行者123 更新时间:2023-11-28 08:18:47 26 4
gpt4 key购买 nike

我的 Google 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 上运行良好。

最佳答案

好吧,我也遇到了同样的问题

对于那些有兴趣查看它的人 - 您可以在这里找到并复制它: 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/

这是迄今为止我能找到的最好的解决方法。

关于javascript - Chrome 中的打印问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23261536/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com