contentWindow.document.execCommand('print', false, null) not working in firefox

后端 未结 2 1548
忘了有多久
忘了有多久 2021-01-16 03:23

I am implementing some print function for iframe now , and i am using below code:

 $(\'#printBtn\').click(function(){
     var iframe = document.getElementBy         


        
相关标签:
2条回答
  • 2021-01-16 04:07

    execCommand('print') is not supported by Firefox.

    https://developer.mozilla.org/en-US/docs/Web/API/document.execCommand

    You can use the print() function instead.

    window.print() ;
    

    https://developer.mozilla.org/en-US/docs/Web/API/Window.print

    You might want to read this: Printing a (part of) webpage with Javascript

    Hope this helps.

    0 讨论(0)
  • 2021-01-16 04:08

    with the help of naota, i fixed this issue for firefox , here is my full solution for printing iframe content, working fine for me .

     $('#printBtn').click(function(){
        var iframe = document.getElementById('previewInfoBodyFrame');
        if(navigator.userAgent.toLowerCase().indexOf("firefox")!=-1){
             iframe.contentWindow.print();              
        }else{
             iframe.contentWindow.document.execCommand('print', false, null);
        }
        return false;     
     } ); 
    
    0 讨论(0)
提交回复
热议问题