gpt4 book ai didi

javascript - 当打印页面出现在javascript中时,如何删除 'Date'和 'Untitled'字母?

转载 作者:行者123 更新时间:2023-12-01 01:28:16 25 4
gpt4 key购买 nike

按下按钮时会出现打印页面。但是我在打印页面中收到不必要的内容,例如:

enter image description here

如何删除这些字段?

我的运行代码是(代码片段不起作用,您可以直接复制粘贴并运行它):

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Page</title>

<script language="javascript" type="text/javascript">
function printDiv(divID) {
//Get the HTML of div
var divElements = document.getElementById(divID).innerHTML;
//Get the HTML of whole page
var oldPage = document.body.innerHTML;

//Reset the page's HTML with div's HTML only
document.body.innerHTML =
"<html><head><title></title></head><body>" +
divElements + "</body>";

//Print Page
window.print();

//Restore orignal HTML
document.body.innerHTML = oldPage;


}
</script>

</head>
<body>
<form id="form1" runat="server">
<div id="printablediv" style="width: 100%; background-color: Blue; height: 200px">
Print me I am in 1st Div
</div>
<div id="donotprintdiv" style="width: 100%; background-color: Gray; height: 200px">
I am not going to print
</div>
<input type="button" value="Print 1st Div" onclick="javascript:printDiv('printablediv')" />
</form>
</body>
</html>

最佳答案

要删除标题,您需要将边距设置为零。

<style type="text/css" media="print">
@page
{
size: auto;
margin: 0mm;
}
</style>

关于javascript - 当打印页面出现在javascript中时,如何删除 'Date'和 'Untitled'字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53551230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com