【问题标题】:Entire page is printing in IE when using jQuery plugin使用 jQuery 插件时在 IE 中打印整个页面
【发布时间】:2013-09-26 10:13:16
【问题描述】:

HTML

<div id="printDiv">
<!-- content Here -->
</div>
<input type="button" value="Print" onclick="printDiv()"/>

JQuery

function printDiv()
{
  $("#printDiv").print();
}

这是在使用 Mozilla Firefox 时打印特定的 div,但在使用 IE(版本 10)时,它正在打印整个页面。

我正在使用这个 jQuery 插件。

jQuery.print.js

请帮帮我。

【问题讨论】:

  • @Kolink 这是这个插件的目的,虽然从来没有自己测试过
  • IE 有没有 jQuery Print a div 插件?

标签: javascript jquery internet-explorer printing


【解决方案1】:

你可以在没有插件的情况下做到这一点。我不知道那个插件是否在做额外的事情。您将不得不编写一个自定义 js 函数来仅打印 div 而不是整个页面...

html

<div id="printDiv">
       //content Here
 </div>

js

function customPrint(id) {
     var cont = $('#'+id).html(),
         pageCont = $('body').children();// Updated

     /*Replace the page content with the div content that needs to be printed*/
     $('body').html(cont);

     /*Print function call*/
     window.print();

     /*Place the original page content back*/
     $('body').html(pageCont);
}

customPrint("printDiv");

更新

function customPrint(id) {
         var cont = $('#'+id),
             pageCont = $('body');

         /*Hide the page content*/
         pageCont.hide();
         cont.show();

         /*Print function call*/
         window.print();

         /*Display back the page content*/
         pageCont.show();
    }

【讨论】:

  • 谢谢..但我正在使用内容占位符..我的网页由 Masterpage 继承...在 asp.net 中
  • 没关系...尝试运行此功能并让我知道它是否有效。
  • Yahooo..它的工作..非常感谢..但打印后页面被击中,直到我刷新它..
  • 卡住了,到底是怎么回事?
  • 实际上..我正在使用 Jquery Flipbook。这不是菜单项受到打击......对不起......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-27
  • 2015-04-03
  • 1970-01-01
  • 2013-07-08
  • 1970-01-01
  • 2012-01-20
相关资源
最近更新 更多