hello, I am having a small problem and i don`t know the reason. I set that 1- If you click Print button then print.php page will be printed automatically. 2- if you submit a form then print.php page will be printed automatically. Problem is on second option. Page gets printed automatically perfect but if i click Print button again it does not print the page again. I am using firefox. <script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> function loadiFrame(src) { $("#iframeplaceholder").html("<iframe id='myiframe' name='myname' src='" + src + "' frameborder='0' vspace='0' hspace='0' marginwidth='0' marginheight='0' width='1' scrolling='no' height='1' />"); } $(function() { $("#printbutton").bind("click", function() { loadiFrame('print.php'); $("#myiframe").load( function() { window.frames['myname'].focus(); window.frames['myname'].print(); } ); } ); }); </script> <? if (isset($_POST['formSubmit'])) { echo "form submitted"; ?> <script type="text/javascript"> $(document).ready(function(){ $('#printbutton').trigger('click'); }); </script> <? } ?> </head> <body> <table border="1"> <tr> <td><input type="button" id="printbutton" value=" Print " /><div id="iframeplaceholder"></div></td> </tr> </table> <form action="auto.php" method="post"> <input name="formSubmit" type="submit" value="Submit" /> </form> </body> Code (markup):
Think I have managed to solve it. According to this post, it's a bug in Firefox. It works if you add a counter that makes each iframe name unique. <script type="text/javascript"> var counter = 0; function loadiFrame(src) { counter++; $("#iframeplaceholder").html("<iframe id='myiframe' name='myname" + counter + "' src='" + src + "' frameborder='0' vspace='0' hspace='0' marginwidth='0' marginheight='0' width='1' scrolling='no' height='1' />"); } $(function() { $("#printbutton").bind("click", function() { loadiFrame('print.php'); $("#myiframe").load( function() { window.frames['myname' + counter].focus(); window.frames['myname' + counter].print(); } ); } ); }); </script> Code (markup):
My one is the latest one. I have to use firefox because it is the only one you can use to print things without having windows print dialog box.
In Firefox, just type “about:config†to address bar and add a new Boolean preference item named “print.always_print_silent†then set value of the newly-added item to “true“. Then it prints without having print dialog box!