I cannot test on device but here:
in section "Content" that is explicitely stated that if html string is loaded via loadString method it cannot load local content (this could lead to exploit otherwise: user provides some links in tags that would fetch content from application sandbox - so fixed (static) local page need to be used to load local content I think),
Thank you, Peter.
I gave that a reading.
It's still a bit unclear.
So can it be done or not? Should I use file: ?
Peter, any idea if it's possible to reference local files with loadString()?
1 person found this helpful
I cannot test on device right now. Reading docs *between lines*:
- write local html page with dynamic content to e.g. application documents directory - this would allow you to use content in dynamic way
- that page would use relative referenced content if available in app documents directory (so it would be needed to copy content to docs directory before first user) or in application storage directory if using absolute URLs (you would need contruct paths using File object and then use its url to get iOS specific path to use in e.g. image src tag.
- having written such dynamic page you would load it using loadUrl(...) not loadString(...) - which will allow you to load local and remote resources - as it will run in applicaiton security context (again: "loadString" is sandboxed as it could load anything into browser instance to be processed even content loaded from maulicious web page).
I assume that you somehow want to build content dynamically at runtime depending on some application state, date, etc, right?
Yeah, it's dynamically build content. I thought about creating the HTML file on the fly, but am worried about:
1. Performance. Create file + write to file + save file + load URL
2. I wouldn't be surprized if loading local content with relative paths still doesn't work even when loading URLs that are relative
3. The mess that could be created from lots of files. I could just always write to one file though...