Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用html打印出没有URL的站点_Javascript_Html - Fatal编程技术网

Javascript 如何使用html打印出没有URL的站点

Javascript 如何使用html打印出没有URL的站点,javascript,html,Javascript,Html,我给出了从页面打印出来的代码。但是页面将与URL一起出现。所以,在打印输出时,URL也会显示在页面中 我的Javascript代码 我的html提交按钮看起来像 <input type="button" id="btnPrint" value="print" onclick="return PrintPanel();" style="color:#FFFFFF; background: none repeat scroll 0 0 #7C8399;border-color: #999999

我给出了从页面打印出来的代码。但是页面将与URL一起出现。所以,在打印输出时,URL也会显示在页面中

我的Javascript代码

我的html提交按钮看起来像

<input type="button" id="btnPrint" value="print" onclick="return PrintPanel();" style="color:#FFFFFF; background: none repeat scroll 0 0 #7C8399;border-color: #999999 -moz-use-text-color #CCCCCC #999999;" />
我还附上了截图。。让我知道有没有可能


您可以通过在窗口中添加选项location=no来实现,但这不会在所有浏览器上都起作用。出于安全原因,您不能在许多最近的浏览器上隐藏地址栏

function PrintPanel() {
    var panel = document.getElementById("pnlContents");
    var printWindow = window.open('', '', 'height=400,width=800,location=0');
    printWindow.document.write('<html><head><title>DIV Contents</title>');
    printWindow.document.write('</head><body >');
    printWindow.document.write(panel.innerHTML);
    printWindow.document.write('</body></html>');
    printWindow.document.close();
    setTimeout(function () {
        printWindow.print();
    }, 500);
    return false;
}

如果您将其转换为pdf格式,然后打开该文件并打印,效果会更好

基于上述概念的在线应用程序是Google Docs。所以,我希望你们采用这种方法。Google文档打印时不带页眉和页脚。

要转换为pdf,请按照此问题的答案进行操作
function PrintPanel() {
    var panel = document.getElementById("pnlContents");
    var printWindow = window.open('', '', 'height=400,width=800,location=0');
    printWindow.document.write('<html><head><title>DIV Contents</title>');
    printWindow.document.write('</head><body >');
    printWindow.document.write(panel.innerHTML);
    printWindow.document.write('</body></html>');
    printWindow.document.close();
    setTimeout(function () {
        printWindow.print();
    }, 500);
    return false;
}