Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: window.reload is not a function

I am trying to print an image from inside a div, the code runs ok but when the print dialog pops up, I would like the page to stay the same while actually it is showing only the picture as the window.reload doesn't work for some reasons. The javascript is telling me in console "Uncaught TypeError: window.reload is not a function"but i don't understand why.

  function printDiv(printableArea) {
    var printContents = document.getElementById("printableArea").innerHTML;
    var originalContents = document.body.innerHTML;
    document.body.innerHTML = printContents;
    window.print();
    window.close();
    window.reload();
  }

Click to print

<input type="button" onclick="printDiv('printableArea')" value="print a div!" />
like image 433
rob.m Avatar asked Dec 03 '15 21:12

rob.m


People also ask

How do I stop Windows reloading my location?

You can use the following code: window. stop();

How do you refresh a JavaScript window?

Window location.reload() The reload() method reloads the current document. The reload() method does the same as the reload button in your browser.

What is location reload () in JavaScript?

The location.reload() method reloads the current URL, like the Refresh button.

Does window location href reload the page?

location. reload() reloads the current page with POST data, while window. location. href='your url' does not include the POST data.


1 Answers

The reason you are getting the error is that there is no window.reload() method. You might want to use location.reload() to reload the page instead.

like image 67
Nathan Hinchey Avatar answered Sep 28 '22 16:09

Nathan Hinchey