javascript - Open a new page in a new window, print it and closed it -


i still can't code work, trying use "onclick" swap image once clicked, open new page in new window, print new opened window , closed it. opens new page on new window, prints blank page , cant close it, seems focus not been set somehow. can 1 me on tis? thanks!

<!doctype html> <html lang="en"> <head> <meta charset="utf-8">  <title>print it</title> <!--style type="text/css" media="print"> .noprint {visibility: hidden;} </style--> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script type="text/javascript"> $(function(){ $(".img-swap").live('click', function() { if ($(this).attr("class") == "img-swap") {   this.src = this.src.replace("_off","_on"); } else {   this.src = this.src.replace("_on","_off"); } $(this).toggleclass("on"); }); }); </script> <script type="text/javascript"> // <!--   popup = {   init : function () {  $('a.action_print').bind('click', popup.printit);     },       printit : function () {          var win = window.open('doc1.html','printed','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=250');          if (win) {             win.document.close();              win.focus();             win.print();         }          return false;     } }  $(document).ready(function () {     popup.init(); });    // --> </script>  </head>  <body>   <br>  click print:<br><br>  <p style=" padding: 125px 0; text-align: center;"> <a class="action_print" target="printed"><img src="images/cam_off.png" class="img-swap" width="100" height="100" /></a> </p>  </body> </html> 

thanks looking!

i figured out, works, had make sure files printing leave in same domain. hope can others in need such thing, improvements on code welcome.

<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>open n print</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type='text/javascript'>//<![cdata[   $(function(){   function openprintwindow(url, name, specs) {     var printwindow = window.open(url, name, specs);     var printandclose = function () {       if (printwindow.document.readystate == 'complete') {         clearinterval(sched);         printwindow.print();         printwindow.close();      }     }         var sched = setinterval(printandclose, 200);    };   jquery(document).ready(function ($) {    $(".test").on("click", function (e) {      var myurl = $(this).attr('data-url');     alert(myurl);      e.preventdefault();     openprintwindow(myurl, "to_print", "width=700,height=400,_blank");    });  });   });//]]>      </script>   </head>  <body>    </br>   <a class="test" href="javascript:;" data-url= "doc.html">open print , close doc</a>   <br />   </body>  </html> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -