Open Base64 in new tab

后端 未结 4 1814
说谎
说谎 2020-12-17 20:00

I have a Base64 encoded document which can be PDF file or image. I would like to create a button in HTML5 page that opens this base64 in a new tab (or new page it does not m

4条回答
  •  难免孤独
    2020-12-17 20:24

    I am adding the answer to my questiion based on Aaron's answer:

    document.getElementById('btnDownload').addEventListener('click', function(){
        var w = window.open('about:blank');
        setTimeout(function(){ //FireFox seems to require a setTimeout for this to 
        work.
    
            w.document.body.appendChild(w.document.createElement('iframe'))
                .src = $this.attr('href');
            w.document.getElementsByTagName("iframe")[0].style.width = '100%';
            w.document.getElementsByTagName("iframe")[0].style.height = '100%';
        }, 0);
    });
    

提交回复
热议问题