简体   繁体   English

如何获取访问网页时自动打开的pdf文档?

[英]how to get a pdf document to automatically open when webpage is accessed?

I'm a bit new to this so bear with me. 我对此有些陌生,请耐心等待。 What I am trying to do is to get a pdf document to open automatically as soon as a webpage is launched. 我正在尝试做的是让pdf文件在网页启动后自动打开。 This webpage will be hosted locally and the pdf document(S) will be stored locally as well. 该网页将在本地托管,并且pdf文档也将在本地存储。

Essentially we are using an external platform that allows buttons to link to exterior webpages, but does not allow for opening documents. 本质上,我们使用的是外部平台,该平台允许按钮链接到外部网页,但不允许打开文档。 What we are trying to do is to bypass this limitation by having a webpage that is locally hosted that will automatically open up a pdf file which will be stored on the device. 我们正在尝试做的是通过拥有本地托管的网页来绕开此限制,该网页会自动打开将存储在设备上的pdf文件。

If the webpage just contained the code <a href"link-to-pdf-doc"></a> will this suffice? 如果该网页仅包含代码<a href"link-to-pdf-doc"></a>就足够了吗?

If you are wanting to embed the pdf in the web page rather than download it, a simple way is to use just a plain html object tag: 如果您想将pdf嵌入网页中而不是下载它,一种简单的方法是仅使用普通的html object标签:

<object data="link-to-pdf-doc" type="application/pdf" width="100%" height="100%">

I am not sure how much support there is in browsers all across the board, but it will work for the majority of modern browsers. 我不确定所有浏览器都将提供多少支持,但是它对大多数现代浏览器都适用。

There are also many libraries available which use browser detection to normalise the code and maybe have wider browser support: 还有许多可用的库,这些库使用浏览器检测来规范代码,并且可能具有更广泛的浏览器支持:

https://github.com/mozilla/pdf.js https://github.com/mozilla/pdf.js

http://pdfobject.com http://pdfobject.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM