简体   繁体   中英

How can I use <img> with a local image on Android?

Using <img> with the src , a local file works fine on a PC. But on Android 7 it doesn't get displayed; instead a no photo icon is displayed. How can I solve this?

<img src="photo.png">

(The photo.png is placed in the same folder as the .html file.)

You have to declare the path of the photo:

<img sc = " xxxpathxxx/"photo.png">

Else, make a separate image folder and call it.

The issue with this is how Webview works with local files. File paths aren't the same as your PC Google Chrome paths where you can drag an HTML file to the browser and have it be loaded in a certain path, and because of that photo.png doesn't direct anywhere.

Instead, you need to use the file:// schema to access local files. Regardless of whether photo.png is local or an Internet resource, you'll need to use photo.png's absolute path, eg:

http://localhost/path/to/photo.png
http://www.mywebsite.com/path/to/photo.png
file://data/local/tmp/photo.png

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