Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
129 views
in Technique[技术] by (71.8m points)

javascript - 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.

Is this possible?

I currently have the popup window open up the same page, but all none of the rows are expanded.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();

(Note the difference between window.open() and document.open()!)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...