以编程方式打印网页 [英] programmatically print a web page

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

问题描述

我正在制作一个自动去网站打印页面的程序,似乎无法使其工作,我尝试了selenium chrome驱动程序,问题是它不起作用。我试过action.sendkeys键ctrl + shift +p无济于事,最大的问题是打印预览弹出窗口。我尝试发送JavaScript命令:window.print(),但chrome中的打印预览以我的方式,因为你需要按回车键。有没有一种方法在JavaScript中模拟按ENTER键?请帮助

I am making a program to automatically go to a website and print a page, Can't seem to make it work, I tried selenium chrome driver, problem is it doesn't work. i tried action.sendkeys keys ctrl + shift + "p" to no avail, biggest problem is print preview pop-up. I tried sending JavaScript command: window.print(), but the print preview in chrome stands in my way, because you need to press enter. Is there a way in JavaScript to simulate the pressing of the ENTER key? Please help

推荐答案

...因为你需要按回车是故意设置的,否则行为将禁止侵扰 。由于JavaScript通常存储在服务器端,并在客户端执行,因此它可以是任何东西。这就是为什么浏览器中的JavaScript实现专注于安全 - 不允许对本地系统进行潜在的危险访问。



毕竟,没有人想在没有用户关注的情况下打印一些东西如果你能做你想做的事,我会认为这是对我的犯罪。计算机和打印机是我的,没有Web应用程序应该决定何时按Enter键。因此,请将其保留为 window.print(); 更好,允许用户使用浏览器菜单打印他们选择支付的任何页面。



奖励:它有一个方面:你可以以不同于屏幕渲染的方式呈现相同的内容。根据使用CSS的媒体,您有不同的CSS样式 @media http://www.w3.org/TR/CSS21/media.html [ ^ ]。



-SA
"…because you need to press enter" is something which was set on purpose, otherwise the behavior would be prohibitively intrusive. As JavaScript is most typically stored on the server side, and executed on the client side, it can be anything. That's why JavaScript implementation in browsers is focused on safety — no potentially dangerous access to the local system is allowed.

After all, no one would like printing something without the user concern. If you could do what you want, I would consider it as a crime against me. The computer and printer is mine, no Web application is supposed to decide form me when to press Enter. So, leave it with window.print(); better yest, allow the users to print any page they choose to pay using the browser menu.

For the bonus: there is one aspect of it: you can render the same content for printing differently from screen rendering. You have have different CSS styles depending the media using CSS @media: http://www.w3.org/TR/CSS21/media.html[^].

—SA


这篇关于以编程方式打印网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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