Window.print doesn't work in IE

后端 未结 4 2146
遥遥无期
遥遥无期 2020-12-19 06:21

I have to print out a div which I\'m doing in the following way:

function PrintElem(elem)
    {
        Popup(elem.html());
    }

    function          


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-19 07:02

    You MUST do a mywindow.document.close() and you may NOT have a space in the window name

    I assume you invoke PrintElem from onclick of something - if that something is a link, you need to return false in the onclick handler!

    Here is how I would do it if I had to

    function PrintElem(elem) { 
        Popup($(elem).html());
    }
    
    function Popup(data) 
    {
        var mywindow = window.open('', 'to_print', 'height=600,width=800');
        var html = ''+
                   ''+
                   ''+
                   data+
                   '';
        mywindow.document.write(html);
        mywindow.document.close();
        return true;
    }
    

    but I am not sure whether or not the window.close() will interfere with the printing

    And why not

    $(function() {
      $('#print_it').click(function(){
        popup($('#itinerario').html());
      });
    });
    

提交回复
热议问题