【发布时间】:2020-11-04 23:28:31
【问题描述】:
我正在尝试使用 Javascript 在新选项卡中打开 PDF 文件。它工作正常,除了标签标题。选项卡标题显示一些随机 GUID。我用的是 Chrome 浏览器。
代码:
var myBlob= new Blob([blob], {type: ‘application/pdf’})
var file = new File([myBlob], "fileName.pdf");
const data = window.URL.createObjectURL(myBlob)
window.open(data)// it is opening the pdf in new tab but tab name is random GUID
所以我有不同的方法:
// it is opening the pdf in new tab but tab name is random GUID` window.open(data,"my custom tab name")// still no luck` window.open(data,"my custom tab name").document.title = "New Page Title!";// Still not working var newWindow = window.open(data,'_blank'); setTimeout(function () { newWindow.document.title = "My Tab Name"; }, 100);// still not working var newWindow = window.open(data, "_blank"); newWindow.addEventListener('load', function() { newWindow.document.title = 'New Title'; });// downloading file not showing in new tab var a = document.createElement('A'); a.href = data; a.download = data; document.body.appendChild(a); a.click(); document.body.removeChild(a);
所以使用了所有方法。我可以在新标签中显示 PDF,但我无法设置标签标题。
谁能帮我解决这个问题?
【问题讨论】:
标签: javascript