javascript - 检测打印(不打印预览)事件 [英] javascript - detect print (not print preview) event

查看:1414
本文介绍了javascript - 检测打印(不打印预览)事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义打印预览页面,当用户打印页面时显示。在此页面之后,用户被定向到浏览器打印预览页面(在此选择打印机,打印选项等)。如果用户实际打印页面,则我想隐藏我的自定义打印预览页面。如果用户取消打印,则我想保留自定义打印预览页面。

I have a custom print preview page that shows up when a user wants to print a page. After this page, the user is directed to the browser print preview page (where you select printer, print options, etc.). If the user actually prints the page, then I want to hide my custom print preview page. If the user cancels the print, then I want to keep the custom print preview page visible.

我需要能够确定用户是否已打印

I need to be able to determine if a user has printed a page.

我读到IE有 onbeforeprint onafterprint

I read that IE has onbeforeprint and onafterprint methods, but wanted to know if there is something that will work for other browsers too.

推荐答案

有一些方法可以使用code>方法,但是想知道是否还有其他浏览器可以使用的方法。晚上,可能不是一个完全匹配的你的问题,因为它不会检测打印和取消被按下之间,但你可以做到这一点,返回到上一个视图。它应该给出非常合理的用户体验。

A little late in the day and possibly not an exact match for your question as it won't detect between print and cancel being pressed, but you could do this to return you to the previous view. It should give a pretty reasonable user experience.

$(".normalContent").hide();
$(".printView").show();
window.print();
$(".normalContent").show();
$(".printView").hide();

这篇关于javascript - 检测打印(不打印预览)事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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