直接为Object标签提供数据

编程入门 行业动态 更新时间:2024-10-24 20:17:12
本文介绍了直接为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标签提供数据

本文发布于:2023-11-25 12:11:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629696.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标签   数据   Object

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!