直接为Object标签提供数据 [英] Providing the Object tag with data directly

查看:55
本文介绍了直接为Object标签提供数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站中嵌入PDF文件,它看起来像这样:

I wanted to embed a PDF file in my website, it looked like this:

<object data="data/PDFTest1.pdf" type="application/pdf" id="data"></object>

但是随后我想首先使用ajax获取文件(在javascript文件中),在JavaScript中编辑它的源代码,然后创建< object> 并将结果数据提供给它.问题是对象在其 data 属性中需要一个url,并且不直接接受实际数据.我该如何处理?

But then I wanted to first Get the file with ajax (in a javascript file), edit it's source code in JavaScript, and then create an <object> and give it the resulting data. The problem is that the Object needs a url in its data attribute, and does not accept the actual data directly. How can I handle this?

有没有一种方法可以创建伪造的网址"?例如在javascript中?

Is there a way to create a "fake url" in javascript for example?

还是我可以通过其他方式将数据传递给对象?

Or can I somehow pass the data in another way to the object?

还是应该使用其他标签?

Or should I maybe use some other tag ?

在此先感谢您的英语.

推荐答案

您实际上不需要URL.您可以将PDF转换为base64,并将data属性设置为数据本身.您只需要在base64前面加上数据:"前缀,然后是mime类型,分号"base64",然后是代表PDF的base64编码字符串.

You don't actually need a URL. You can convert the PDF to base64 and set the data attribute to the data itself. You just need to prefix the base64 with "data:" then the mime type, a semi-colon, "base64," and then the base64 encoded string that represents the PDF.

<object data="data:application/pdf;base64,YOURBASE64DATA" type="application/pdf"></object>

这篇关于直接为Object标签提供数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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