I am trying to print contents of a DIV by creating a new window element that holds the html I would like to print. Everything works and the css styling is shown correctly on the print-preview window but the styling is lost when the window is physically printed to a file or printer. I suspect that the print() event is fired before the css is loaded but not sure how can I fix this.

Here's my js code

```
  function printDiv (elem)
  {
    var popup = window.open('','','width=800,height=500,toolbar=no, menubar=no');
    popup.document.writeln('<!DOCTYPE html>');
    popup.document.writeln('<html><head><title></title>');
    popup.document.writeln('<link rel="stylesheet" type="text/css" href="/assets/css/main.css">');
    popup.document.writeln('</head><body class="popup-body">');
    popup.document.writeln(elem.html());
    popup.document.writeln('</body>');
    popup.document.writeln('</html>');
    popup.print();
    popup.close();
}

```