如何用开放的base64 PDF内容的新窗口? [英] How open new window with base64 PDF content?

查看:680
本文介绍了如何用开放的base64 PDF内容的新窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开新窗口(使用jQuery),并从显示的base64内容PDF。当我做正常的链接:

 < A HREF = \\的数据:;'。$答案 - > shipping_label_content应用程序/ PDF格式的base64,\\目标= \\空白\\>显示PDF&LT ; / A>

这一切都很好。但我想这个内容自动开启新的窗口,我不知道如何: - /

  VAR窗口= window.open();
VAR HTML =数据:应用程序/ PDF格式; BASE64,'$&答案 - GT; shipping_label_content。'$(window.document.body)的.html(HTML);


解决方案

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

  //这一招会生成一个临时< A />标签
变种链路= document.createElement方法(一);
link.href =数据:应用程序/ PDF格式; BASE64,'$&答案 - GT; shipping_label_content。'//设置属性您明智的
link.download =SomeName;
link.target =空白;//这部分将追加锚标记和自动点击之后将其删除
document.body.appendChild(链接);
link.click();
document.body.removeChild(链接);

I want open new window (with jQuery) and show PDF from base64 content. When I make normal link:

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

It's all good. But I want automatic open new window with this content and I don't know how :-/

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

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

解决方案

You can generate a temp anchor and click programmatically.

//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);

这篇关于如何用开放的base64 PDF内容的新窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆