Google Chrome 不会打印我的 Javascript 和 AJAX 生成的内容
我是一个网络应用程序的开发人员。
Chrome 可以正确显示我的 Javascript 和 AJAX 生成的网页,但是当我尝试打印它们(通过其本机功能)时,我得到一个空白页面。
打印在其他浏览器上运行良好。
我尝试过用 Chrome 打印服务器端生成的页面,它们打印得很好。
我的 Web 应用程序的网页可能出现什么问题?我认为问题在于这些页面是由 Javascript 和 AJAX 动态生成的。
我这么说是因为我刚刚发现我什至无法使用 Chrome 正确保存这些页面(所有动态 HTML 都没有显示)。
我使用的是 Google Chrome 13.0.782.112。
我该如何调试并解决这个问题? 有什么解决方法吗? 有人设法用 Google Chrome 打印动态生成的内容吗?
这个问题快把我逼疯了!
PS:我的一些用户在 Safari 上报告了同样的问题:-(
更新:升级到 Chrome 14.0.835.202 但问题仍然存在...
I am the developer of a webapplication.
Chrome displays my Javascript-and-AJAX-generated webpages correctly, but when I try and print them (via its native function) I get a blank page.
Printing works just fine on other browsers.
I have tried and print server-side-generated pages with Chrome and they get printed fine.
What can be wrong on the webpages of my web application? I think the issue is that those pages are dynamically generated by Javascript and AJAX.
I am saying that because I have just found out that I can't even save those pages correctly with Chrome (all the dynamic HTML is not shown).
I am on Google Chrome 13.0.782.112.
How can I debug and fix this issue?
Is there any workaround?
Is anybody managing to get dynamic-generated content printed with Google Chrome?
This problem is driving me crazy!
P.S.: some of my users are reporting the same problem on Safari :-(
UPDATE: upgraded to Chrome 14.0.835.202 but the issue is still there...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了完全相同的问题,尽管不是在 Chrome 中(尽管我实际上没有用 Chrome 进行测试)。在某些浏览器上(我一时记不起是哪些浏览器 - 但它要么是在 IE 中,要么是 FF 中),通过 JavaScript 添加到 DOM 中的任何内容都不会打印。实际打印的是提供给浏览器的原始文档。
我使用以下 JavaScript 函数成功解决了这个问题:
当 JavaScript 页面操作完成时调用此函数。它实际上读取整个 DOM,然后使用
document.write
将整个文档重新写入自身。现在,我可以在 IE 和 FireFox 上打印我的特定项目,尽管我很确定其中一个已经可以工作,而另一个则不能(记不清是哪个,而且它是不是我现在可以拿出来测试的项目)。我不知道这是否能解决 Chrome 中的问题,但值得一试。编辑非常抱歉,但我是一个十足的平民。我刚刚重新阅读了我的旧评论,这个解决方案与打印无关;它实际上是为了解决保存到文件时仅保存原始服务文档的问题。然而,话虽如此,我仍然想知道是否值得一试。
I've had exactly the same problem, though not in Chrome (although I didn't actually test with Chrome). On certain browsers (and I cannot remember which ones offhand - but it was either in IE or FF), any content that is added into the DOM by JavaScript is not printed. What is actually printed is the original document that was served to the browser.
I successfully solved this using the following JavaScript function:
This is called when JavaScript page manipulation has finished. It actually reads the entire DOM and then re-writes the whole document back into itself using
document.write
. This is now enabling printing for my particular project on both IE and FireFox, although I'm pretty sure one of those did already work in the first place, and the other one didn't (can't remember which from memory, and it's not a project I can pull out to test at the moment). Whether this will solve the problem in Chrome I don't know, but it's worth a try.Edit Terribly sorry, but I'm a complete pleb. I just re-read my old comments and this solution had nothing to do with printing; it was actually to fix a problem where only the original served document would be saved when saving to file. However, that said, I still wonder if it's worth a shot.
这帮助我解决了一个相关问题 - 如何查看/保存动态生成的 HTML 本身。我想出了以下书签。
我运行它并“全选”/复制,然后(在 Linux 中)执行“xclip -out”将大量剪贴板数据定向到文件。
This helped me with a related problem - how to view/save dynamically generated HTML itself. I came up with the following bookmarklet.
I run this and 'select all' / copy, and then (in Linux) do 'xclip -out' to direct the large amount of clipboard data to a file.
特雷弗的回答完全适合我 - 使用 jquery 我只是做了一些类似的事情
,完美地工作
Trevor's answer totally worked for me- with jquery I simply did something like
worked perfectly