javascript - Print current html page in next page onclick -


i need print current html page in new page using button attribute 'onclick()' used follwing

javascript  function printpartofpage(elementid)  {   var printcontent = document.getelementbyid(elementid);   var windowurl = 'p2p money transfer';   var uniquename = new date();   var windowname = 'p2p money transfer  -' + uniquename.gettime();     var printwindow = window.open(windowurl, windowname, 'left=50000,top=50000,width=0,height=0');     printwindow.document.write(printcontent.innerhtml);   printwindow.document.close();   printwindow.focus();   printwindow.print();   printwindow.close();  }  </script>
<input type="button" value="print" onclick="javascript:printpartofpage('printdiv');" >

but problem there no style implemented,so need current entire html page transfer method , write using document.write() has styles in it.

i suggest use printthis jquery library achieve goal.

with library can print part of page (example div) , decide use css of page or external css add parameter. here list of parameters

$("#myselector").printthis({  *      debug: false,               * show iframe debugging  *      importcss: true,            * import page css  *      importstyle: false,         * import style tags  *      printcontainer: true,       * grab outer container contents of selector  *      loadcss: "path/to/my.css",  * path additional css file - array [] multiple  *      pagetitle: "",              * add title print page  *      removeinline: false,        * remove inline styles print elements  *      printdelay: 333,            * variable print delay  *      header: null,               * prefix html  *      formvalues: true            * preserve input/form values  *  }); 

as can see there property importstyle , if set true script load same scripts of page. can load external css property loadcss.

i have used , works well.

look @ this fiddle example


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -