javascript - 使用javascript打印图像

标签 javascript image popup printing

我想知道是否可以使用 javascript 打开包含图像的弹出窗口,同时显示打印对话框。一旦有人点击打印,弹出窗口就会关闭。

这很容易实现吗?

最佳答案

另一个很好的解决方案!!所有功劳归功于 Codescratcher

<script>

    function ImagetoPrint(source)
    {
        return "<html><head><scri"+"pt>function step1(){\n" +
                "setTimeout('step2()', 10);}\n" +
                "function step2(){window.print();window.close()}\n" +
                "</scri" + "pt></head><body onload='step1()'>\n" +
                "<img src='" + source + "' /></body></html>";
    }

    function PrintImage(source)
    {
        var Pagelink = "about:blank";
        var pwa = window.open(Pagelink, "_new");
        pwa.document.open();
        pwa.document.write(ImagetoPrint(source));
        pwa.document.close();
    }

</script>

<a href="#" onclick="PrintImage('YOUR_IMAGE_PATH_HERE.JPG'); return false;">PRINT</a>

查看完整示例 here .

关于javascript - 使用javascript打印图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2909033/

相关文章:

javascript - Illustrator ExtendScript save() 方法

html - 为什么 CSS mask-image 不能使用 no-repeat?

android - 有没有办法在从 URL 加载的按钮上设置图标(可绘制)?

html - 我无法将图像左对齐,然后将页脚标记内的文本与图像的右侧对齐

ios - 从弹出 ViewController Swift 继续

javascript - 如何为基于 KOA 的服务器生成 API 文档

javascript - 为什么我的 div 只在我添加 isopen=true 的属性时才动画,但在我将值更改为 false 时却不动画

javascript - JS 弹出窗口

javascript - 手动 Angular 销毁指令

c# - 在 xaml 中定义时如何避免创建多个弹出窗口?