使用Javascript在“新建浏览器”选项卡中使用自定义磁贴打开PDF blob文件

使用Javascript在“新建浏览器”选项卡中使用自定义磁贴打开PDF blob文件,javascript,Javascript,我正在尝试使用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)// i

我正在尝试使用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
所以我有不同的方法:

  • 所以我们使用了所有的方法。我可以在新选项卡中显示PDF,但无法设置选项卡标题


    有人能帮我吗?

    类似的方法很有效:

    const newWindow = window.open()
    newWindow.document.title = 'My Tab Name'
    newWindow.document.write`<iframe src="${URL.createObjectURL(myBlob)}" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>`)
    
    const newWindow=window.open()
    newWindow.document.title='My Tab Name'
    newWindow.document.write``)
    
    // 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); 
    
    const newWindow = window.open()
    newWindow.document.title = 'My Tab Name'
    newWindow.document.write`<iframe src="${URL.createObjectURL(myBlob)}" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>`)