从网站自动打印图像 [英] Automatically Print Image from Website

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

问题描述

我和一位同事正在讨论浏览器中哪些是可行的,哪些是不可能的.

A coworker and I were having a discussion about what is and isn't possible within the browser.

然后出现了一个问题,我们都无法肯定地回答.

Then a question came up that neither of us could answer with certainty.

您能否创建一个网页,以便当您导航到该网页时,它会与客户端打印机连接并尝试打印文档.例如,每当你访问我的个人网站时,你都会看到一张我微笑的照片.

Can you create a webpage such that when you navigate to it, it engages the client-side printer and attempts to print a document. For instance, whenever you visit my personal website, you'll be treated to a print out of a picture of me, smiling.

现在,这是一个可怕的想法.我意识到.但是讨论让我很感兴趣,它是否可以完成,以及如何完成.我的朋友坚持认为你能做的最好的事情就是为用户弹出打印对话框,他们必须自己点击打印.

Now, this is a hideous idea. I'm aware. But the discussion intrigued me as to if it could be done, and how. My friend insisted that the best you could do was pop up the print dialog for the user, they would have to click print themselves.

是否可以绕过这一步?或者只是一些花哨的脚本来将鼠标移到打印按钮上并单击它?还是使用一个 ActiveX 控件直接与打印机 API 交互?

Would it be possible to bypass this step? Or just some fancy script to move the mouse over the print button and click on it? Or use an activeX control to interface with a Printer API directly?

推荐答案

你必须提示用户打印当前页面,没有办法绕过这一步(可能在activeX for IE中).也就是说,您可以通过两种不同的方式提示用户在页面加载时打印您微笑的图像.

You have to prompt the user to print the current page, there's no way to bypass this step (possibly in activeX for IE). That said, there's two different ways you could prompt the user to print images of you smiling when the page is loaded.

这是在 JavaScript 中的操作方法.

Here's how to do it in JavaScript.

window.onload = function() {
  var img = window.open("me-smiling.png");
  img.print();
}

这里是如何在 css/javascript/html 中执行此操作(假设您的图片具有 id 'me-smiling'):CSS:

And here's how to do it in css/javascript/html (assuming your picture has the id 'me-smiling'): CSS:

@media print {
   * {
     display:none;
   }
   img#me-smiling {
     display:block;
   }
}

Javascript:

Javascript:

 window.onload = function() { window.print() }

这篇关于从网站自动打印图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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