将当前网页复制到新窗口 [英] Copy Current Webpage Into a New Window
问题描述
我需要能够将当前网页复制到新的弹出窗口以进行打印预览。页面上有一个带子项的网格,所以如果他们展开其中一行来查看子行,我需要在新窗口中显示它。
I need to be able to copy the current webpage into a new popup window for a print preview. There is a grid on the page with children, so if they expand one of the rows to see the child rows, I need to show this in the new window.
是这可能吗?
我目前有弹出窗口打开同一页面,但所有行都没有展开。
I currently have the popup window open up the same page, but all none of the rows are expanded.
推荐答案
也许这就行了(在IE和Firefox中,不在Opera中。不知道WebKit):
Perhaps this does the trick (in IE and Firefox, not in Opera. Don't know about WebKit):
var yourDOCTYPE = "<!DOCTYPE html..."; // your doctype declaration
var printPreview = window.open('about:blank', 'print_preview');
var printDocument = printPreview.document;
printDocument.open();
printDocument.write(yourDOCTYPE+
"<html>"+
document.documentElement.innerHTML+
"</html>");
printDocument.close();
(注意 window.open()$ c $之间的区别c>和
document.open()
!)
然而,你将丢失所有自定义DOM内容,例如事件处理程序等。尽管如此,如果您只是想复制'粘贴HTML。
However, you will lose all custom DOM thingies, like event handlers and so on. Nonetheless, it might work if you just want to copy 'n paste your HTML.
这篇关于将当前网页复制到新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!