用window.print()打印,ie怎么没有预览

-一个大坑 2017-09-12 09:22:23
一直用谷歌调试,都没发现,在ie上右键打印有预览;
网上搜的ExecWB(7, 1); 提示錯誤: 物件沒有支援這個屬性或方法 'ExecWB'

$(function () {
$("#btnPrint").click(function () {
$.ajax({
url: '/SCRP0101/GetPrintSendCar',
type: "GET",
data: { appDT: $("input[name='appDT']").val()},
success: function (data) {
bdhtml = $("#disposeDiv").empty().append(data).html();
sprnstr = "<!--startprint-->";
eprnstr = "<!--endprint-->";
prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
window.document.body.innerHTML = prnhtml;
window.print();
location.href = "SCRP0101";
},
error: function (msg) {
alert('失败了,可能后台报错');
},
});
})
});
...全文
1378 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
-一个大坑 2017-09-15
  • 打赏
  • 举报
回复
引用 6 楼 zhujiazhi 的回复:
打印用Lodop试试的
打不开这个网站,权限管的很严
zhujiazhi 2017-09-14
  • 打赏
  • 举报
回复
打印用Lodop试试的
-一个大坑 2017-09-14
  • 打赏
  • 举报
回复
-一个大坑 2017-09-13
  • 打赏
  • 举报
回复
没有用print打印的吗
-一个大坑 2017-09-13
  • 打赏
  • 举报
回复
引用 3 楼 jjkk168 的回复:
为何需要预览?如果在没有指定css的属性为仅在打印时显示的情况下,页面中见到的不就是需要打印出来的内容么?测试只要通过了,充分相信打印出来的结果就行。
多张打印,有预览就可以直接打印指定的那张
还想懒够 2017-09-13
  • 打赏
  • 举报
回复
为何需要预览?如果在没有指定css的属性为仅在打印时显示的情况下,页面中见到的不就是需要打印出来的内容么?测试只要通过了,充分相信打印出来的结果就行。
-一个大坑 2017-09-12
  • 打赏
  • 举报
回复
【利用WebBrowser彻底解决Web打印问题(包括后台打印) 】利用WebBrowser彻底解决Web打印问题(包括后台打印)BS架构下的打印大家是怎么解决的呢,我最近作了一个项目正好负责这一块,不仅要求打印页面的特定部分,还要求有后台的批量打印,在网上查了一些资料,最后终于解决了。抱着“取之于众 服务于众”的思想,我总结了一下,把它拿到网上来与大家分享,希望能帮助遇到类似问题的朋友。我主要使用了IE内置的WebBrowser控件,无需用户下载和安装。WebBrowser有很多功能,除打印外的其他功能就不再赘述了,你所能用到的打印功能也几乎全部可以靠它完成,下面的问题就是如何使用它了。先说显示后打印,后面说后台打印。1.首先引入一个WebBrowser在需要打印的页面,可以直接添加:到页面,或者使用JavaScript在需要的时候临时添加也可以:document.body.insertAdjacentHTML("beforeEnd","");2 .页面设置和打印预览如下所示,直接调用即可document.all.WebBrowser.ExecWB(6,6) 直接打印document.all.WebBrowser.ExecWB(8,1) 页面设置document.all.WebBrowser.ExecWB(7,1) 打印预览或者:execScript("document.all.WebBrowser.ExecWB 7, 1","VBScript");3 隐藏不打印的页面元素和分页CSS 有个Media 属性,可以分开设置打印和显示的格式。如 … 中间的格式将只在打印时起作用,不会影响显示界面。所以可以设定.Noprint{display:none;}.PageNext{page-break-after: always;}然后给不想打印的页面元素添加: class="Noprint" ,那就不会出现在打印打印预览中了。想分页的地方添加: 就可以了。4.打印页面的特定部分我是通过将需要打印的特定部分另建一个页面,然后装入主页面的一个IFrame中,再调用IFrame的打印方法,只打印IFrame中的内容实现的。如:下面的pringFrame js函数将只打印Iframe中的内容,可以直接引用使用,如printFrame(FrameId);window.print = printFrame;// main stufffunction printFrame(frame, onfinish) {if ( !frame ) frame = window;function execOnFinish() {switch ( typeof(onfinish) ) {case "string": execScript(onfinish); break;case "function": onfinish();}if ( focused && !focused.disabled ) focused.focus();}if (( frame.document.readyState !== "complete") &&( !frame.document.confirm("The document to print is not downloaded yet! Continue with printing?") )){execOnFinish();return;}var eventScope = printGetEventScope(frame);var focused = document.activeElement;window.printHelper = function() {execScript("on error resume next: printWB.ExecWB 6, 1", "VBScript");printFireEvent(frame, eventScope, "onafterprint");printWB.outerHTML = "";execOnFinish();window.printHelper = null;}document.body.insertAdjacentHTML("beforeEnd","");printFireEvent(frame, eventScope, "onbeforeprint");frame.focus();window.printHelper = printHelper;setTimeout("window.printHelper()", 0);}// helpersfunction printIsNativeSupport() {var agent = window.navigator.userAgent;var i = agent.indexOf("MSIE ")+5;return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;}function printFireEvent(frame, obj, name) {var handler = obj[name];switch ( typeof(handler) ) {case "string": frame.execScript(handler); break;case "function": handler();}}function printGetEventScope(frame) {var frameset = frame.document.all.tags("FRAMESET");if ( frameset.length ) return frameset[0];return frame.document.body;}Iframe中所装载页面的打印效果在所装载页面设置就可以了,如分页等。5.后台打印我是通过建一个隐藏Iframe实现的,当然仍然会有页面装载的过程。下面的函数创建Iframe装载页面并打印。如 printHidden(url) //url为页面地址function printHidden(url) {document.body.insertAdjacentHTML("beforeEnd","");var doc = printHiddenFrame.document;doc.open();doc.write("");doc.write("");doc.write("");doc.close();}function onprintHiddenFrame() {function onfinish() {printHiddenFrame.outerHTML = "";if ( window.onprintcomplete ) window.onprintcomplete();}printFrame(printHiddenFrame.printMe, onfinish);}它用到了printFrame,所以别忘了引用前面的函数。总之,WebBroswer已经为我们提供了解决方案,我们只要结合需求把它应用好就行了。
一套功能强大,可取代记事本的文字编辑器,拥有无限制的 Undo/Redo、英文拼字检查、自动换行、列数标记、搜寻取代、同时编辑多文件、全屏幕浏览功能。而它还有一个好用的功能,就是它有监视剪贴簿的功能,能够同步于剪贴簿自动将文字贴进 EditPlus 的编辑窗口中,让你省去做贴上的步骤。另外它也是一个好用的 HTML 编辑器,除了可以颜色标记 HTML Tag (同时支持 C/C++、Perl、Java) 外,还内建完整的 HTML 和 CSS1 指令功能,对于习惯用记事本编辑网页的朋友,它可帮你节省一半以上的网页制作时间,若你有安装 IE 3.0 以上版本,它还会结合 IE 浏览器于 EditPlus 窗口中,让你可以直接预览编辑好的网页 (若没安装 IE,也可指定浏览器路径)。 更新日志 Version 4.3.1256 (2017-05-12) * Updates Emmet integration. * FTPS now supports TLS 1.1 and TLS 1.2. * HTTP proxy option now allows username and password. * Allows different default encoding for each file type. * ‘Browser’->’Zoom’ menu command added. * ‘Edit’->’Others’->’Extend Number Selection’ menu option added. * ‘Record Keystroke’ now records ‘Window’->’Next’/’Previous’/’Last Visited’ commands. * Allows Find Next/Previous shortcut keys from Find dialog box. * Saving remote file could fail without error message in some cases. * ‘Upload to a temp file then rename’ ftp option could break symbolic link. * Opening remote file from command line could cause program crash. * Fixes a possible error when using FTP proxy server. * -t command line option didn’t work with remote files. * ‘Auto save as *.tmp file’ could overwrite untitled files. * Fixes a Perl auto completion issue. * Fixes incorrect left margin when printing. * Fixes inaccurate word wrap in print and print preview mode. * Fixes an issue where ‘Log File Watch’ sometimes couldn’t detect changes. * Fixes an issue where restoring split window state sometimes wouldn’t work correctly. * Fixes an issue where $(CurSel) argument macro couldn’t handle multi-line text. * Fixes possible program crash with files in right-to-left languages.

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧