Question

Backstory(or what i am trying to do)

I have a webview in my app that loads an html file from assets folder. The file has 2 iframes in it.

Then user imports some zip files in app which include additional files to be loaded in these iframes. I load these files by passing their file:// urls to a javascript function on the main page(the one with 2 iframes), rest is javascript. Then the main page injects some additional js and javascript to after user files are loaded in iframes. Everything is working fine.

Problem

All fine. Except when the file is an xhtml file. The injected javascript has some dom manipulation functions which does not work when file is loaded as text/xhtml. I have the pc version of the same app which uses chromium embedded framework, i solved that problem there by writing a custom resource loader that loads all xhtml files with text/html mimetype.

What i tried so far

I tried to do the same in the android version. Except i do not have anyway to target an iframe inside the webview in java side.

I am using shouldOverrideUrlLoading(WebView view, String url) and returning true if it's a .xhtml url. I thought(because of the function's counterpart in CEF) the first arg in that function would be the iframe and used loadDataWithBaseUrl. Turns out it's not the iframe but the main webview itself.

Question

Is there anyway to load data to a iframe from java, with a similiar function? if not do you have any suggestions on transferring such files as a text/html instead of text/xhtml.

Or is there anything i can do on the javascript side?

Was it helpful?

Solution

Okay,

Solved this case by renaming .xhtml files to .html files while importing.

But still webviews are lacking at accessing the iframes from java case. Solved that by using individual webviews instead of iframes.

I guess i have to use parts of chromium source(ChromeView) to be able to access inner frames. Although api is not similiar or compatible to WebView, i can go with chromeviews own api.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top