简体   繁体   中英

redirect to previous page after page printed

i developed a system and i have some pages that i want to print right after page loaded.

for example i want to print USERS page right after page was loaded, and i use this method:

window.addEventListener("load", () => {
  window.print();
});

it works but I want to redirect to previous page right after page was printed and i tried this way:

window.addEventListener("load", () => {
  window.print();
  history.back();
});

but its not work, it redirect after page was loaded, not wait to print the page then redirect to previous page

You can try afterprint .

window.addEventListener("load", () => {
  window.onafterprint = function(){
    history.back();
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM