调用window.print()时会触发什么事件? [英] What event is fired when window.print() is called?
问题描述
我正在努力解决这个问题,今晚我的成功很少。如果我只知道在调用 window.print()
函数时触发了什么事件,我想我可以使下面的代码工作。
I am trying to work through this question and I have had little success tonight. I think I can make the code below work if I only knew what event was fired when the window.print()
function is called.
var browser_name = navigator.appName;
if(browser_name == 'Microsoft Internet Explorer'){
window.attachEvent("print()",on_print_function);//I realize I cannot attach an event listener to a function, I just wanted you to see what I am trying to accomplish
}
else{
window.addEventListener("print()",on_print_function,false);
}
打印时调用的函数
事件发生返回一个页面,该页面存储数据库中的一些信息。
The function that is called when the print
event takes place returns a page that stores some info in the database.
我的最终目标是,如果相关信息是将存储在数据库中。 我愿意接受更好的方法解决这个问题,但我认为如果我能够获得 print()
的事件,我会好的。 。
My end objective is to have the page print ONLY if the info in question is going to be stored in the database. I am open to better ways of tackling this, but I think I will have it going ok if I can just get the event for the print()
as I said.
编辑
我放弃了这个现在,我已经采取了另一种做我想做的方式。我期待着FireFox支持 onbeforeprint()
和 onafterprint()
的那一天。
I am giving up on this for now, I have settled with another way of doing what I want. I look forward to the day when FireFox supports onbeforeprint()
and onafterprint()
.
推荐答案
据我所知,IE有几个事件行onbeforeprint()和onafterprint()但是其他浏览器不支持它们。所以依靠这个并不是很好。
Well as far as I know, IE has several events line onbeforeprint() and onafterprint() but they are not supported by other browsers. So relying on this is not very good.
也许你的页面上有一个打印按钮。附加一个处理程序,它执行对服务器的ajax调用以将数据存储到数据库,并且在此调用成功时,调用窗口上的print()。
Perhaps you can have a print button on your page. Attach to it a handler which executes the ajax call to the server to store the data to the database and on success of this call, call the print() on the window.
那是你在找什么?
这篇关于调用window.print()时会触发什么事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!