打印后功能无法单击其他选项卡 [英] After print function not able to click other tabs

查看:95
本文介绍了打印后功能无法单击其他选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用默认的打印功能进行打印,但是一旦完成打印功能,我将无法单击其他选项卡.在同一页面中打开打印"窗口

I am using a default print function for printing, but once print function is completed i am not able to click other tabs. Print window is opening in the same page

function printReport() {
    var divElements = $('.nicEdit-main').html();
    var oldPage = document.body.innerHTML;
    document.body.innerHTML = "<html><head><title></title></head><body>" + divElements + "</body>";
    window.print();
    document.body.innerHTML = oldPage;
}

推荐答案

不幸的是,您只是替换了整个页面. innerHTML仅返回HTML 减去处理程序和附加到元素的任何数据的字符串形式.设置innerHTML会从该字符串中重新创建DOM,而没有原始附加的处理程序.您只是有效地"使页面瘫痪了!

Unfortunately, you just replaced the entire body of your page. innerHTML only returns a string form of the HTML minus the handlers and any data attached to the elements. Setting the innerHTML recreates the DOM from that string without the handlers that were originally attached. You just "effectively" paralyzed the page!

我建议:

  • 最困难的方法是继续执行您的操作,但是将所有处理程序委派给document,就像live那样将其删除以免被删除.困难,可能但不可扩展,不可维护或最佳.

  • The hard way would be to continue what you are doing, but delegate all handlers to document like how live would have done it so that they won't be removed. Hard, possible, but not scalable, maintainable or optimal.

或者您可以只创建一个隐藏的iframe并将内容打印在那里.然后改为从该iframe window调用print.这样,您就不会丢失当前页面.

Or you could just create a hidden iframe and place your content to be printed there. Then call print from that iframe window instead. That way, you won't lose your current page.

其他人会创建一个新窗口,在其中放置内容,运行打印并在之后立即将其关闭.与iframe一样,但您不希望像某些弹出广告一样立即打开和关闭的令人毛骨悚然的窗口.

Others would create a new window, put content there, run print and close it immediately after. Works the same as iframes, but you wouldn't want a creepy window that opens and closes immediately like some pop-up ad.

这篇关于打印后功能无法单击其他选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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