Javascript to direct to a page and print (physically)

Asked

Viewed 171 times

0

Good morning. I’m starting in javascript, but I urgently need to learn a task, which in my view seems relatively easy, but I’m not getting it. Following:

Has the example site.com.br/2.html

I need to create a javascript that takes the user (in this case I) from page 3.html to 100.html and for each page that loads, print it automatically.

For now I’ve managed to get to the code:

window.location.href = "exemplo.com.br/2.html";window.print()

But when I put this code to run, print the page I’m on and after that I’m directed to the code page, and not the other way around, like I wanted it to be. But other than that, how do I order the browser to go to the next page after that print?

  • If this screen is accessed only by this way, you can put the window.print(). Look at my writing!!

  • Why don’t you put the remote window.print() when loading the page that was directed (in the event onload)? In your case 2.html, 3.html and so on. That way, when redirect and the page is loaded will print

  • Ricardo, I tried to leave it like this: window.onload = print() but it keeps printing before loading. Can you help me? (I’m starting JS now)

  • Dude, I think it’s best that you generate a server-only page with all the content and on this page, give window.print(). I explain: Each time you do this, the user needs to confirm the print and sometimes even, depending, configure it. See if it’s really worth doing like this...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.