2016-09-26 68 views
0

我已经写了下面的函数来调用另一个页面,当我点击打印按钮。但是当我点击打印按钮时,它会打开当前页面而不是我想打电话的页面。点击如何打开另一页?

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; 
    } 
+0

可能重复[有没有一种方法来改变window.location.href后有一个onload回调?](http://stackoverflow.com/questions/13811582/is-there-a-way-to-have-一个-的onload-回调之后变化的窗口,位置的HREF) –

回答

1

您遇到的问题是您设置window.location.href后的代码立即执行。该页面未加载,然后代码继续...您继续执行代码直到函数结束,然后window.location.href实际加载并处理。如果你明白我的意思。

您可以尝试将代码(window.print,如果window.stop等)移动到ViewTripConformationPrint.cshtml(作为onload的一部分)。

相关问题