[英]After cancel or save print dialog the current window was not close
when I print the data then it open new windows with all respective data of HTML page and in small amount of time open print dialog but when I cancel that dialog or close the dialog at that time the the current window not close. 当我打印数据时,它将使用HTML页面的所有相应数据打开新窗口,并在短时间内打开打印对话框,但是当我取消该对话框或在那时关闭该对话框时,当前窗口不会关闭。
Please suggest how to close back window of dialog box after close print dialog. 请在关闭打印对话框后建议如何关闭对话框的后窗口。
Here is my code to print data: 这是我的打印数据代码:
$.ajax({ url: "project/printProjectData?" + this.searchdata, cache: false, dataType: 'html', contentType: 'application\\'html', success: function(html){ var w = window.open(''); w.document.open(); w.document.write('<html><head>'); w.document.write('</head><body onload="window.print()">'); w.document.write(html); w.document.write('</body></html>'); w.document.close(); CheckWindowState(); } }); function CheckWindowState() { if(document.readyState === "complete") { window.close(); } else { setTimeout("CheckWindowState()", 2000) } }
but still not close the new opened window. 但仍不能关闭新打开的窗口。
// Just pass w object to your function so it can close that window using that object //只需将w对象传递给函数,以便它可以使用该对象关闭该窗口
$.ajax({
url: "project/printProjectData?" + this.searchdata,
cache: false,
dataType: 'html',
contentType: 'application\'html',
success: function(html){
var w = window.open('');
w.document.open();
w.document.write('<html><head>');
w.document.write('</head><body>');
w.document.write(html);
w.document.write('</body></html>');
w.print();
CheckWindowState(w);
}
});
function CheckWindowState(window) {
if(document.readyState === "complete") {
window.close();
} else {
setTimeout("CheckWindowState()", 2000)
}
}
you could use setTimeout, if you want to wait for n seconds and then close 如果要等待n秒然后关闭,则可以使用setTimeout
var delayInMilliseconds = 1000; //1 second
setTimeout(function() {
//your code to be executed after 1 second
}, delayInMilliseconds);
I have found the way to close the loaded window after print or cancel. 我找到了在打印或取消后关闭加载的窗口的方法。
As I am print the data after onload event same we have to close the window on same onload event. 当我在onload事件之后打印数据时,我们必须在相同的onload事件上关闭窗口。
printProjectData: function () { $.ajax({ url: "project/printProjectData?" + this.searchdata, cache: false, dataType: 'html', contentType: 'application\\'html', success: function(html){ var w = window.open(); w.document.write('<html><head>'); w.document.write('</head><body onload="window.print(); window.close();">'); w.document.write(html); w.document.write('</body></html>'); w.document.close(); } }); },
Thanks all.:) 谢谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.