Open blob objectURL in Chrome

后端 未结 6 1611
挽巷
挽巷 2020-12-24 06:22

I want to open a PDF in a new tab in chrome browser (Chrome 56.0.2924.87, Ubuntu 14.04) using window.open(fileObjectURL) in javascript. I am creating the blob f

6条回答
  •  别那么骄傲
    2020-12-24 07:16

    In plain vanilly javascript (because I don't have jquery)

    let newWindow = window.open('/file.html');
    newWindow.onload = () => {
        var blobHtmlElement;
        blobHtmlElement = document.createElement('object');
        blobHtmlElement.style.position = 'fixed';
        blobHtmlElement.style.top = '0';
        blobHtmlElement.style.left = '0';
        blobHtmlElement.style.bottom = '0';
        blobHtmlElement.style.right = '0';
        blobHtmlElement.style.width = '100%';
        blobHtmlElement.style.height = '100%';
        blobHtmlElement.setAttribute('type', 'application/pdf'); 
        blobHtmlElement.setAttribute('data', fileObjectURL);
        newWindow.document.title = 'my custom document title';
        newWindow.document.body.appendChild(blobHtmlElement);
    };
    

    /file.html is an almost empty html file, source:

    
    
    
    
    
    
    
    
    

    Tested in chrome & firefox (on 20/november/2019)

提交回复
热议问题