搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

Learn More

Cannot reload page by reload JS function after click print button

  • 無回覆
  • 1 有這個問題
  • 13 次檢視
more options

I wrote a JS function in order to print the modal window in the page and reload page link after print done. But I faced problem that after I click print button, the reload function didn't working. Below are the JS source code

<script language="javascript" type="text/javascript"> function printDiv(divName) {

 var printContents = window.document.getElementById(divName).innerHTML;
 document.body.innerHTML = printContents;
 window.print();

// window.location.href= window.location.href; // window.history.go(0); }; window.onafterprint = function() {

   window.location.reload(true);

}; </script>

I wrote a JS function in order to print the modal window in the page and reload page link after print done. But I faced problem that after I click print button, the reload function didn't working. Below are the JS source code <script language="javascript" type="text/javascript"> function printDiv(divName) { var printContents = window.document.getElementById(divName).innerHTML; document.body.innerHTML = printContents; window.print(); // window.location.href= window.location.href; // window.history.go(0); }; window.onafterprint = function() { window.location.reload(true); }; </script>