How to print a redirected page?

Asked

Viewed 37 times

0

In my case, has the home page, in it has the options to enter the post and print the page of the post, without having to enter the post. Like I’m walking into a page and printing it.

1 answer

0


Using the function print()Javascript is not possible without some tricks.

An alternative you could do is load the page you want to print using the method $.load() Jquery, save all the contents of the current page in some variable, set the contents of the page with the return of the $.load() and use the print() to print this new content, finally return the contents of the original page.

The method print() I just printed what’s on the screen, not an external content. Therefore, it is necessary to bring the external content to the current screen, print, and return the original content.

Something more or less like this:

var original = $("html").html(); //pega todo o conteudo original da pagina.
var pagina;
$(pagina).load("url-da-pagina", function() {
    $("html").html(pagina); //vamos pegar todo o conteudo da nova pagina
    window.print(); //imprimi
    $("html").html(original); //retorna conteudo original
});
  • Thank you so much for the help, any doubts I return in this post !!!!

Browser other questions tagged

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