简体   繁体   中英

How to open pdf in external browser from an app's webview instead of open it?

In my app's webview, the webpage contains link which point to a pdf file. Like this:

<a href="https://test.com/Pdf.htmsmh?dyF3jeTQ%2BwSah4RixlvIPcawMnJI%2F5Jm" target="_blank">Window Sticker</a>

When click this link, the browser selection pop up and ask me to select the browser which I want to open the app, currently there are default browser and Chrome.

However, when I select the browser, both of them are downloading this pdf file into the phone, but not opening it.

Just wonder, how could I let the browser directly open the pdf, but not downloading them?

Thank you!

I am not aware of any Web browsers on Android that directly render PDFs themselves. If the browser is downloading the PDF, that is because it does not handle the PDF itself, and it is allowing the user to then view the PDF in their chosen PDF viewer app.

The only way you are going to get a browser to render a PDF itself is if you load something that is itself a PDF renderer (eg, Mozilla's pdf.js ) and have it render your PDF. Note that this is fairly uncommon in Android at the moment, and I have no idea if pdf.js in particular works on the major Android browsers.

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