In my case, there is the home page, in it you have the options to enter the post and to print the page of the post, without having to enter the post. Like if you went into a page and printed it.
In my case, there is the home page, in it you have the options to enter the post and to print the page of the post, without having to enter the post. Like if you went into a page and printed it.
Using the print()
JavaScript function is not possible without some tricks.
One alternative you could do is to load the page you want to print using the $.load()
method of JQuery, save all the contents of the current page to some variable, set page contents with $.load()
, and use the print()
to print this new content, finally, to return the content of the original page.
The print()
method only prints what is on the screen, not an external content. So you need to bring the external content to the current screen, print it, and return the original content.
Something 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
});