trigger('click') problem

Discussion in 'jQuery' started by baris22, Nov 8, 2010.

  1. #1
    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):

     
    baris22, Nov 8, 2010 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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):
     
    Cash Nebula, Nov 13, 2010 IP
    baris22 likes this.
  3. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    thanks alot. you can`t image how much this helped me.
     
    baris22, Nov 14, 2010 IP
  4. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You're welcome :)

    I'm surprised the bug has not been fixed yet, that post is more than two years old! :eek:
     
    Cash Nebula, Nov 15, 2010 IP
  5. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #5
    who knows, maybe baris22 firefox is older than 2 years as well :S hope not lol
     
    stephan2307, Nov 16, 2010 IP
  6. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #6
    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.


     
    baris22, Nov 16, 2010 IP
  7. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #7
    do you mean you can print directly without any dialog box when you use firefox??
     
    stephan2307, Nov 16, 2010 IP
  8. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #8
    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!




     
    baris22, Nov 16, 2010 IP