1

After clicking the print button, page should automatically redirect to another page. I attached the screenshot and code below:

enter image description here

javascript

<script>
        myFunction();

        function myFunction()
        {

                window.print();
             //  setTimeout(closePrintView(), 3000);
        }
            function closePrintView() {
                window.location.href = 'purchase3.php';
            }

    </script>

in this code before printing page redirected

alimbaronia
  • 504
  • 2
  • 10
creative one2018
  • 131
  • 2
  • 11
  • 1
    Welcome to StackOverflow. Please check ["How do I ask a good question?"](https://stackoverflow.com/help/how-to-ask). It is not clear what you want to accomplish. – Ale Jul 26 '18 at 05:39
  • I think put `window.location.href = 'purchase3.php';` before `window.print()` – Rendi Wahyudi Muliawan Jul 26 '18 at 05:41
  • 2
    Can you let us know why do you want to redirect to another page? Showing them a PDF using `Content-Disposition:inline` should be enough. – nice_dev Jul 26 '18 at 05:46
  • i am developing pos system. after complete, the sales form page redirect to print page after click print form. page redirect sales form again. – creative one2018 Jul 26 '18 at 05:50
  • Have a look at [this question](https://stackoverflow.com/questions/18325025/how-to-detect-window-print-finish). It may help you to achieve what you're trying to – Rylee Jul 26 '18 at 05:58

1 Answers1

3

You can use window.onafterprint to fire other script codes after it is printed.

window.onafterprint = function(e){
    closePrintView();
};

function myFunction(){
    window.print();
}

function closePrintView() {
    window.location.href = 'https://bing.com';   
}
<button onClick="myFunction()">Print</button>
Hari Das
  • 10,145
  • 7
  • 62
  • 59