2016-09-26 61 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的一部分)。

相關問題