如何在asp.net中不显示printdialog进行打印 [英] how to print without show printdialog in asp.net

查看:86
本文介绍了如何在asp.net中不显示printdialog进行打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net中打印不显示printdialog

how to print without show printdialog in asp.net

推荐答案

你不能。打印需要花钱,因此如果网页可以强制打印,那将是非常烦人的。如果用户想要打印,他们会。
You can't. Printing costs money so it would be incredibly annoying if web pages could force print. If the user wants to print they will.


你不能。网站取决于客户的网络浏览器软件。执行以下功能的时间,



You cannot. A website is dependent on the client's web browser software. The time when you execute the following function,

window.print();





浏览器会执行它;它不会向操作系统发送调用来处理此代码。执行后,浏览器会显示一个对话框;基于软件架构师,用户可以打印文档,编辑文档或(如在谷歌浏览器中)将文档保存为PDF等等。根据 MDN [ ^ ],上面的函数打开对话框。





The browser would execute it; it won't send a call to the OS to handle this code. Upon executing, browser would show a dialog; based on the software architect and would enable the user to either print the documents, edit the documents or (as in Google Chrome) save the document as PDF and so on and so forth. As per MDN[^], the above function opens the dialog.

Quote:

打开打印对话框以打印当前文档。

Opens the Print Dialog to print the current document.





这只是为了确保用户(确实)想要打印文档而代码不是某种类型的bug或病毒等。就像,即使我可以写一个简单的JavaScript代码,例如,





This is just to make sure, that the user (does) want to print the document and the code is not some type of bug or a virus etc. Like, even I can write a simple JavaScript code, such as,

for (var v in times) {
  // times = 10;
  window.print();
}





会发生什么?你很清楚。 :)这就是为什么,浏览器试图告诉用户当前网页有什么意图。我相信这是一个很好的用户体验;对用户有帮助。对于用户来说,从他的打印机开始接收页面并不是一个好主意。



What would happen? You know well. :) That is why, browser tries to tell the user what intent did the current web page had. I believe this is a good user-experience; helpful for user. For user to start receiving pages from his print machine won't be that much better idea.


除了解决方案1和我对它的评论:



打印页面的最简单方法不是用户,而是脚本(客户端,但总是可以在服务器端启动)是JavaScript 窗口。 print()

http://www.w3schools.com /jsref/met_win_print.asp [ ^ ] 。



当然,JavaScript实现应该是显示对话框所必需的。不这样做只会是愚蠢和有害的。请注意,整个JavaScript理念将其作为最重要的原则之一:安全,与客户端系统隔离,不直接对客户端系统做任何事情。



-SA
In addition to Solution 1 and my comment to it:

The simplest way to print a page triggered not be the user but by script (client-side, but it's always possible to initiate on the server side as well) is JavaScript window.print():
http://www.w3schools.com/jsref/met_win_print.asp[^].

But of course, JavaScript implementation is supposed and required to show the dialog. Not doing it would be just silly and harmful. Note that that the whole philosophy of JavaScript includes it as one of the most important principle: safety, isolation from the client system, not doing anything to the client system directly.

—SA


这篇关于如何在asp.net中不显示printdialog进行打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆