javascript - 如何打印弹窗内容和主要内容

标签 javascript jquery printing popup

我想打印页面的内容。但其中包含一个弹出窗口。我需要在我的主页中显示包含按钮名称“详细信息”的弹出窗口内容。当我单击该按钮时,将显示一个弹出窗口。

当我单击打印按钮时。仅显示主要内容。弹出显示窗口的特定字段为空(详细信息按钮)

我正在使用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/

相关文章:

javascript - 在 Javascript 中向过滤器函数添加条件

javascript - 提交前使用 javascript 进行 HTML 表单验证

javascript - 仅在轴的起点和终点刻度

javascript - 使用 YouTube iframe API 触发简单事件/使用player.getCurrentTime 同步事件

c# - 提高图像的打印质量

java - 使用 Java 打印服务在 Java 中打印不同尺寸的页面

javascript - window.print() 随机停止工作。它的调用有限制吗?

php - 为什么这个 javascript 变量没有被设置到 php 中的 cookie 中?

jQuery:在实时 jQuery 中计算顶部

javascript - 使用 .each() jquery 进行多个选择框值测试