Javascript 我们能用一次点击打印单独的html页面吗

Javascript 我们能用一次点击打印单独的html页面吗,javascript,Javascript,我们可以用一次点击打印单独的html页面吗?否 但是,您可以创建一个新页面,其中包含要打印的每个页面的内容(可能使用媒体选择器仅在屏幕上显示摘要),然后单击两次即可打印该页面(一次单击打开打印对话框,另一次单击“确定”) [更新]: 随着我的深入思考,您可能会使用javascript将页面作为弹出窗口加载,然后为每个加载的页面打开打印对话框。不过,这对用户来说不是一个很好的体验。不 但是,您可以创建一个新页面,其中包含要打印的每个页面的内容(可能使用媒体选择器仅在屏幕上显示摘要),然后单击两次即

我们可以用一次点击打印单独的html页面吗?否

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

[更新]: 随着我的深入思考,您可能会使用javascript将页面作为弹出窗口加载,然后为每个加载的页面打开打印对话框。不过,这对用户来说不是一个很好的体验。

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

[更新]:
随着我的深入思考,您可能会使用javascript将页面作为弹出窗口加载,然后为每个加载的页面打开打印对话框。不过,这对用户来说不是一个很好的体验。

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

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


来源:

尝试将特定CSS用于打印模式

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


来源:

我知道Internet Explorer在“打印选项”中有打印此页面以及所有链接页面的选项。您可以创建一页链接到您想要的所有页面,然后在启用该设置的情况下打印该页面



(来源:)

我知道Internet Explorer在“打印选项”中有打印此页面以及所有链接页面的选项。您可以创建一页链接到您想要的所有页面,然后在启用该设置的情况下打印该页面



(来源:)

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

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();
  }
};
printHtml=函数(html){
var frame=top.document.getElementById(IFRAME\u ID);
如果(!帧){
frame=top.document.createElement('IFRAME');
frame.id=IFRAME\u id;
frame.style.width='1px';
frame.style.height='1px';
top.document.body.appendChild(frame);
frame.contentWindow.document.open();
frame.contentWindow.document.write(“”);
frame.contentWindow.document.write(“”);
frame.contentWindow.document.write(
'');
frame.contentWindow.document.write(html);
frame.contentWindow.document.write(“”);
frame.contentWindow.document.close();
}
};

我想,您可以创建iFrame并打印任意次数,尽管每页都会显示“打印选项”对话框。

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

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();
  }
};
printHtml=函数(html){
var frame=top.document.getElementById(IFRAME\u ID);
如果(!帧){
frame=top.document.createElement('IFRAME');
frame.id=IFRAME\u id;
frame.style.width='1px';
frame.style.height='1px';
top.document.body.appendChild(frame);
frame.contentWindow.document.open();
frame.contentWindow.document.write(“”);
frame.contentWindow.document.write(“”);
frame.contentWindow.document.write(
'');
frame.contentWindow.document.write(html);
frame.contentWindow.document.write(“”);
frame.contentWindow.document.close();
}
};

我想,您可以创建iFrame并打印任意次数,尽管每页都会显示“打印选项”对话框。

如果您通过“单击”将不同的网页发送到打印机,则可以,但是,您可能希望在问题上展开一点,以便我们能够更准确地帮助您。如果您通过“单击”将不同的网页发送到打印机,则可以,但您可能希望在问题上展开一点,以便我们能够更准确地帮助您。