简体   繁体   中英

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. This webpage will be hosted locally and the pdf document(S) will be stored locally as well.

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.

If the webpage just contained the code <a href"link-to-pdf-doc"></a> will this suffice?

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:

<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

http://pdfobject.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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