Relative Path in Html

How to set relative path to current folder?

Just dot is working. The doctype makes a difference however as sometimes the ./ is fine as well.

<a href=".">Link to this folder</a>

Relative paths in HTML from `filesDir` won't work

I believe you need to call setAllowFileAccess in WebSettings to enable access to file:// URLs, as they're disabled by default in API 30 and above.

webview.getSettings().setAllowFileAccess(true);

html linking , relative path

Your code is valid, but you might be mistaken in the location of the files your linking to. That would result in an invalid url.

Have a look at a folder structure as below. You've got a project folder name project-example this folder contains the index.html and the folders templates and images.

If you want to link in your index.html to the files in those folders the src or href would have to be something like templates/style.css or images/image.png.

example of a folder structure



Related Topics



Leave a reply



Submit