Skip to content

why can’t i set window.onload in IE8?

I have the following function, which works fine in Firefox, but will do nothing in IE8

function print(url) {
    var w = window.open(url);
    w.onload = function() {
        w.print();
    };
}

I want to open a webpage and immediately open the print dialogue.

Answer

If you have the hand on the page at url, place the call there. In the HTML, at the end of the BODY tag. Add a SCRIPT tag with your call

<body>
  ...
  <script>
    window.print();
  </script>
</body>