Print a div with data from ajax or jquery.get()

前端 未结 3 1492
耶瑟儿~
耶瑟儿~ 2021-01-15 17:56

I have a div:

that gets populated by JQuery using innerHTML with strings from client side jav

3条回答
  •  情话喂你
    2021-01-15 18:22

    Try using a hidden iframe:

    $('#submit').click(function (e) {  
        e.preventDefault();     
        $('#contract').empty();    
        var profile = $('#profile').val();
        var query = {
            profile: profile
        };
        $.get('/foo/profileViewer', query, function (data) {            
            $('body').append('');
            $('#printf').contents().find('body').append(data);
             window.frames["printf"].focus();
             window.frames["printf"].print();       
        })
    });
    

    https://jsfiddle.net/njezoem5/

提交回复
热议问题