-1

I'm using the following javascript to print a page then I want to redirect after either canceling or accepting the print.

<script type="text/javascript">
    window.print();

    window.location.replace("URL");
</script>

Everything works but when I add the window.location it adds a full blank page before the pages I'm printing.

Yunath
  • 15
  • 7
  • you should do something more reliable: http://stackoverflow.com/questions/1234008/detecting-browser-print-event – Daniel A. White Dec 08 '16 at 18:55
  • I just need a quick print nothing fancy. And all the page is doing is printing so i don't need a before print after print functionality – Yunath Dec 08 '16 at 19:09

2 Answers2

0

you need to add a property in CSS @page{margin:0}

you can try this code :

<!DOCTYPE html>
<html>
<head>
    <title>tp</title>
<style type="text/css">
@page{
      margin: 0mm;
}
    *{
        padding: 0;
        margin: 0;
        background: red;
    }
</style>

</head>
<body>
<p>test</p>
<script type="text/javascript">
    window.print();
    window.location.replace("http://www.google.com");
</script></body>
</html>
h3t1
  • 1,126
  • 2
  • 18
  • 29
0

Although I didn't solve the problem, I fixed it by having the page open in a new tab so I can avoid a redirect altogether.

Yunath
  • 15
  • 7