【问题标题】:How open new window with base64 PDF content?如何使用 base64 PDF 内容打开新窗口?
【发布时间】:2015-06-03 04:10:09
【问题描述】:

我想打开新窗口(使用 jQuery)并显示来自 base64 内容的 PDF。当我建立正常链接时:

<a href=\"data:application/pdf;base64,'.$answer->shipping_label_content.'\" target=\"blank\">Show PDF</a>

一切都好。但我想用这个内容自动打开新窗口,我不知道怎么做:-/

var window = window.open();
var html = "data:application/pdf;base64,'.$answer->shipping_label_content.'";

$(window.document.body).html(html);

【问题讨论】:

    标签: javascript jquery base64


    【解决方案1】:

    您可以生成一个临时 anchor 并以编程方式单击。

    //this trick will generate a temp <a /> tag
    var link = document.createElement("a");
    link.href = "data:application/pdf;base64,'.$answer->shipping_label_content.'";
    
    //Set properties as you wise
    link.download = "SomeName";
    link.target = "blank";
    
    //this part will append the anchor tag and remove it after automatic click
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
    

    【讨论】:

    • 这项工作,如 window.open("data:application/pdf;base64,'.$answer->shipping_label_content.'", "_blank", '');但是 Safari 第一和第二个被阻止了:-/
    • 此解决方案不适用于 IE。是否有任何替代解决方案可以在 IE 中实现此功能?
    • @Siddharth_Vyas,你可以看看FileSaver
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-01
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    • 2019-01-25
    • 2013-07-18
    相关资源
    最近更新 更多