gpt4 book ai didi

javascript - javascript打印的窗口标题

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:05:07 27 4
gpt4 key购买 nike

找到这段代码来打印我修改过的 javascript 元素。虽然我添加了 document.title<title></title>标签,在常规文本编辑器中打开的窗口显示 untitled .

这通常是文本保存之前的情况。有没有办法显示标题?

    var element=document.getElementById(element_id);
var newWin=window.open('','Print-Window','width=400,height=400,top=100,left=100');

newWin.document.open();
newWin.document.title = "Readings on PageLinks";
newWin.document.write('<html><head><title>'+newWin.document.title+'</title></head><body onload="window.print()">'+element.innerHTML+'</body></html>');
newWin.document.close();

setTimeout(function(){ newWin.close(); },10);

最佳答案

实际上原始代码也适用于我(Chrome,没有在其他浏览器上测试)

var element_id = "id1";
var element = document.getElementById(element_id);
var newWin = window.open('', 'Print-Window', 'width=400,height=400,top=100,left=100');

newWin.document.open();
newWin.document.title = "Readings on PageLinks";
newWin.document.write('<html><head></head><body onload="window.print()">' + element.innerHTML + '</body></html>');
newWin.document.close();

setTimeout(function() {
newWin.close();
}, 10);​

参见 JSFiddle

关于javascript - javascript打印的窗口标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10523036/

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