我们可以一键打印单独的html页面

时间:2009-04-06 13:37:52

标签: javascript

我们可以一键打印单独的html页面

4 个答案:

答案 0 :(得分:1)

尝试使用特定的CSS进行打印模式。

<link rel="stylesheet" type="text/css" media="print" href="print.css">

来源:http://www.javascriptkit.com/dhtmltutors/cssmedia.shtml

答案 1 :(得分:0)

没有。

但您可以创建一个新页面,其中包含您要打印的每个页面的内容,可能使用媒体选择器仅在屏幕上显示摘要),以及在两个点击中打印该页面(单击打开打印对话框,然后单击“确定”)。

[更新]: 当我考虑更多时,您可以使用javascript将页面加载为弹出窗口,然后打开每个加载页面的打印对话框。不过,这对用户来说不是一次非常好的体验。

答案 2 :(得分:0)

我知道Internet Explorer在打印选项中有选项可以打印此页面以及所有链接页面。您可以创建指向所需页面的单页链接,然后打开该设置进行打印。


(来源:tas.gov.au

答案 3 :(得分:0)

我认为这是可能的,但不确定可移植性。我正在开发一个可以在Internet Explorer下运行的富内部网应用程序(因此我不知道它的可移植性)并使用了这样的函数:

printHtml = function(html){
  var frame = top.document.getElementById(IFRAME_ID);
  if (!frame) {
    frame = top.document.createElement('IFRAME');
    frame.id = IFRAME_ID;
    frame.style.width = '1px';
    frame.style.height = '1px';
    top.document.body.appendChild(frame);

    frame.contentWindow.document.open();
    frame.contentWindow.document.write('<html><head>');
    frame.contentWindow.document.write('<link type="text/css" rel="StyleSheet" media="all" href="style.css"/>');
    frame.contentWindow.document.write(
        '</head><body onload="window.focus();window.print();top.document.body.removeChild(top.document.getElementById(\''
            + IFRAME_ID + '\'));">');
    frame.contentWindow.document.write(html);
    frame.contentWindow.document.write('</body></html>');
    frame.contentWindow.document.close();
  }
};

我想,您可以创建iframe并多次打印,但每个页面都会显示打印选项对话框。