window.print() working in chrome but not working in safari

I want to implement print functionality in which I want to print one paragraph and image.I am getting paragraph in chrome but not image. I am getting image and text in firefox but in safari I am getting nothing. How can I make this work?

Thank you

<html>
<head>
<script type="text/javascript">
  function openWin()
  {
  	
    var myWindow=window.open('','','width=1200,height=1000');
    myWindow.document.write("<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse vitae mi aliquet, pharetra risus ut, viverra nunc. Nam feugiat lacinia eleifend. Duis et varius dui, et porta turpis. Curabitur sed sagittis elit, id commodo est. Ut porta blandit arcu vel consectetur. Vivamus pulvinar, libero quis tristique molestie, quam eros semper lacus, eu imperdiet diam arcu ac nisi. Vivamus faucibus consectetur molestie. Aliquam suscipit pretium mi, bibendum laoreet urna convallis eget. Sed vitae consequat ipsum. Suspendisse pretium faucibus ipsum at lacinia. Suspendisse potenti. Nullam ut neque quis orci elementum tristique. Ut quis massa dui.</p> <img src= 'https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940'></p>");
    myWindow.document.write("");
    myWindow.document.close();
    myWindow.focus();
    myWindow.print();
    myWindow.close();
  }
</script>
</head>
<body>

<input type="button" value="Open window" onclick="openWin()" />

</body>
</html>

1 answer

  • answered 2018-08-17 05:12 Ravikiran Gambhire

    Following solution worked for me. I have used setTimeOut function so that it will give enough time to load image after that it pass control to print.

     setTimeout(function() {
         myWindow.print();
         myWindow.close();
        }, 250);