我编写了以下函数,当我单击打印按钮时调用另一个页面。但是当我单击打印按钮时,它会打开当前页面,而不是我想要调用的页面。
function printme(tripId, requestId, Ecommerce) {
//alert("print is called");
alert(tripId);
alert(requestId);
alert(Ecommerce);
window.location.href = "ViewTripConformationPrint.cshtml?";
window.print();
//workaround for Chrome bug - https://code.google.com/p/chromium/issues/detail?id=141633
if (window.stop) {
location.reload(); //triggering unload (e.g. reloading the page) makes the print dialog appear
window.stop(); //immediately stop reloading
}
return false;
}
最佳答案
您遇到的问题是设置 window.location.href 后的代码会立即执行。页面未加载,然后代码继续...您的代码将继续,直到函数结束,然后实际加载并处理 window.location.href 。如果你明白我的意思。
您可以尝试将代码(window.print、if window.stop 等)移至 ViewTripConformationPrint.cshtml(作为 onload 的一部分)。
关于javascript - 打印时点击如何打开另一页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39695022/