复制当前网页到新窗口 [英] Copy Current Webpage Into a New Window

查看:28
本文介绍了复制当前网页到新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够将当前网页复制到新的弹出窗口中以进行打印预览.页面上有一个带有子项的网格,因此如果他们展开其中一行以查看子行,我需要在新窗口中显示它.

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()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屋!

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