我想打印页面的内容。但其中包含一个弹出窗口。我需要在我的主页中显示包含按钮名称“详细信息”的弹出窗口内容。当我单击该按钮时,将显示一个弹出窗口。
当我单击打印按钮时。仅显示主要内容。弹出显示窗口的特定字段为空(详细信息按钮)
我正在使用window.print();
打印按钮=> 'onclick="printpage()"'
功能
function printpage()
{
$('#hiddendiv').html($('#view_popup_descriptive_index').html());
$('#hiddendiv').show();
window.print();
$('#hiddendiv').hide();
}
任何显示弹出内容的方法。
最佳答案
您可以尝试在打印之前将弹出窗口中的 HTML 附加到页面。
$("#print").on('click', function(){
//find HTML
var $popupContent = $('.popup').html();
//console.log($popupContent); //see what you really get from the popup
//create a div before the button and put the popup content there
$(this).before($('<div />', {
'class': 'created',
'html': $popupContent
}));
//trigger printing
window.print();
//remove the dynamically created container
$('.created').remove();
})
您可以在此处看到它在线运行 - https://jsfiddle.net/skip405/6dt2dhm7/
关于javascript - 如何打印弹窗内容和主要内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35030954/