如何用base64 PDF内容打开新窗口?
我想打开新窗口(使用jQuery)并从base64内容显示PDF。 当我做正常链接时:
shipping_label_content.'\" target=\"blank\">Show PDF
都很好。 但是我想用这个内容自动打开新窗口,我不知道如何: – /
var window = window.open(); var html = "data:application/pdf;base64,'.$answer->shipping_label_content.'"; $(window.document.body).html(html);
您可以生成临时anchor
并以编程方式单击。
//this trick will generate a temp 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);