Javascript印刷版 [英] Javascript Print dailog

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

问题描述



我正在使用Javascript print()函数来打印页面.

但是我需要打印后的页面返回到上一页.

我写了以下代码:

Hi,

I am using Javascript print() function for print the page.

But i Need the after print the page is go back to the previouse page.

I have write following code:

function PrintAndBack()
    {
        window.print();
        history.go(-1);
    }







<input id="btnPrint" type="button" value="Print" onclick="PrintAndBack()" />



当用户单击打印"模拟"按钮上的确定"按钮时,打印完成并且页面返回上一页.

但是,当用户单击取消"按钮时,我想在同一页面上停止此用户,而不会返回上一页.

在此先感谢



when user click on OK button on Print Dailog button Print is done and page is going back page.

But when user click on cancel button I want to stop this user on same page not going to back page.

Thanks in advance

推荐答案

您好,

在回答您的问题(尽管我承认这是相当不满意的)时,您现在想做的qhat是不可能的.调用window.print()后,您无法检测到是单击了取消还是打印按钮.您唯一的选择是执行以下操作,询问用户是否希望重定向(或是否打印但询问,但对用户而言透明度较低...)

Hi there,

In answer to your question (though I admit it is rather dissatisfying) qhat you wish to do is currently impossible. You cannot detect whether the cancel or print button was clicked after calling window.print(). Your only alternative is to do something like the following to ask the user if they wish to be redirected (or if they printed but asking that would be less transparent to the user...)

function PrintAndBack()
{
    window.print();
    if(confirm("Would you like to go back?"))
    {
        history.go(-1);
    }
    return false;
}


<input id="btnPrint" type="button" value="Print" onclick="return PrintAndBack();" />



请注意额外的return语句-如果未重定向用户,则单击按钮后这些将阻止页面刷新.如果用户是用户,则他们没有任何区别.

希望这会有所帮助,
Ed



Notice the extra return statements - these stop the page from refreshing after the button click if the user isn''t being redirected. If the user is, then they make no difference.

Hope this helps,
Ed


如果这仅用于IE,则可以使用onafterprint(警告-打印预览将触发它以及实际打印)事件-除此之外,无法知道如何它回来了.

http://msdn.microsoft.com/en-us/library/windows/apps/hh441285.aspx [ ^ ]
If this is solely for IE you can use the onafterprint (warning - print preview will fire it as well as actually printing) event - outside of that, there is no way of knowing how it returned.

http://msdn.microsoft.com/en-us/library/windows/apps/hh441285.aspx[^]


这篇关于Javascript印刷版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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