使用javascript打印的问题 [英] Problem for printing using javascript

查看:63
本文介绍了使用javascript打印的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个打印问题,我正在为打印div编写javascript函数.
在我的div中,我正在为员工创建工资单.因此,我为每个员工分配了div值并进行打印.所以我在循环中调用javascript函数.但是循环完成后,打印窗口将打开.
另一个问题是我想使用默认打印机自动打印div,而无需打开对话框怎么做?使用javascript.帮帮我...
谢谢...我的JavaScript函数是

I have a two problem for printing I am writing javascript function for print div.
In my div I am creating payslip for employee. So I assign the values that div for every employee and print. So I call javascript function in loop. But the print window is open when the loop is finished.
And another problem is I want to print div automatically with default printer, without opening dialogue box how to do it? using javascript. help me...
Thank u.....My javascript function is

function PrintDiv() {
    var divToPrint = document.getElementById("<%=Printable.ClientID%>");
    var popupWin = window.open('', '_blank', 'width=300,height=300');
    popupWin.document.open();
    popupWin.document.write('<html><body  önload='window.print();'>' + divToPrint.innerHTML + </html>');
            popupWin.document.close();
}

for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chkselect");
            if (chk.Checked)
            {

                Salaryproccess();
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Script", "PrintDiv();", true);
            }
        }

推荐答案

作为开发人员和用户,我个人讨厌这种行为(跳过打印对话框).

这是我对MS Word的#1烦恼,谢天谢地,大多数应用程序都没有效仿.

通常,我至少可以访问4台打印机,甚至可以访问更多打印机...以及打印到文件或PDF的功能.

如果我没有机会选择:(a)什么打印机,(b)什么纸张尺寸,(c)什么方向,(d)什么比例,(e)彩色vs.黑白,和(f )什么打印质量,我都很沮丧.

这些是用户选项和首选项.除非您有充分的理由避免使用这些选项,否则请不要删除用户的选择.

2012年11月27日

基本上,打印对话框是Web浏览器中内置的安全功能.

设想一种情况,您访问Domino的网站订购比萨饼,而无需单击页面上的任何内容,打印机将开始在连接到计算机的打印机上打印比萨饼菜单,直到打印机缺纸.您会满意吗?

因此,除非用户批准打印操作,否则浏览器不允许打印.由于这是浏览器功能,因此您无法覆盖它.

下面的评论中提到的针对您的方案的解决方法是生成一个100页的pdf,一次可打印100页.
As a developer, AND a user, I personally HATE this behavior (skipping the print dialog).

This is my #1 annoyance with MS Word, thank goodness most applications didn''t follow suit.

I typically have access to at least 4, if not more printers... plus the ability to print to a file, or a PDF.

If I don''t get the opportunity to pick: (a) what printer, (b) what paper size, (c) what orientation, (d) what scale, (e) color vs. black & white, and (f) what print quality, I get very upset.

These are user options and preferences. Unless you have a very good reason to avoid uses choosing these options, please do not remove the users choice.

27 Nov 2012

Basically the print dialog is a security feature built into the web browsers.

Imagine a scenario where you visit a Domino''s website to order pizzas and without clicking anything on the page , your printer begins printing the pizza menus on the printer attached to your machine until the printer runs out of paper. Will you be happy with it?

So the browser does not allow to print unless the user approves the print action. Since this is a browser feature , you cannot override it.

The workaround for your scenario mentioned in your comment below is to generate a 100 page pdf for printing 100 pages at a time.


这篇关于使用javascript打印的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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