gpt4 book ai didi

javascript - Css 在 javascript 打印功能中不起作用

转载 作者:行者123 更新时间:2023-11-28 15:16:41 26 4
gpt4 key购买 nike

我有一个javascript函数来打印一个由按钮调用的特定div。它像我想要的那样工作但没有样式。问题是当我尝试将div样式添加到该函数时,打印预览显示空白页Chrome(Firefox 运行良好)。我的功能代码是:

    function printDiv(event) {
var DocumentContainer = document.getElementById("page-wrap");

var html = '<html><head>'+
'<link href="./css/style.css" rel="stylesheet" type="text/css"/>'+
'</head><body style="background:#ffffff;">'+
DocumentContainer.innerHTML+'</body></html>';

var WindowObject = window.open("", "PrintWindow",
"width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes");
WindowObject.document.writeln(html);
WindowObject.document.close();
WindowObject.print();
WindowObject.close();
}

谁能帮帮我?

最佳答案

使用css媒体查询

 @media print

并在打印中应用您想要的样式

关于javascript - Css 在 javascript 打印功能中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42561182/

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