jquery - Print another page using JavaScript from a page by clicking on a button -
i have html page button allows printing of specific content following code:
<div class="below_movie_left" id="printablearea"> printing contents </div> <input type="button" class="submit_button" onclick="printdiv('printablearea')" value="print" style="float:right;" /> <script> function printdiv(divname) { var printcontents = document.getelementbyid(divname).innerhtml; var originalcontents = document.body.innerhtml; document.body.innerhtml = printcontents; window.print(); document.body.innerhtml = originalcontents; } </script>
well, it's printing specific content perfectly. but, want print page using button. page name finalprinting.php
so want, when press print button it's should print finalprinting.php
page instead of existing contents of page.
you need use ajax.
<input type="button" id="loadpage" value="print"> <script> document.getelementbyid( "loadpage" ).addeventlistener( "click", function(){ var request = new xmlhttprequest(); request.open("get", "finalprinting.php", true); request.onload = function(){ if (request.status >= 200 && request.status < 400){ // got data, can set body's innerhtml document.body.innerhtml = request.responsetext; } else { // reached our target server, returned error } }; request.onerror = function() { // there connection error of sort }; request.send(); }); </script>
Comments
Post a Comment