Copy Current Webpage Into a New Window

前端 未结 4 1142
有刺的猬
有刺的猬 2020-12-03 08: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 s

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 08:52

    Perhaps this does the trick (in IE and Firefox, not in Opera. Don't know about WebKit):

    var yourDOCTYPE = ""+
                   document.documentElement.innerHTML+
               "");
    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.

提交回复
热议问题