简体   繁体   中英

Android WebView: shouldOverrideUrlLoading called when svg or webm are in object tag in HTML

I am testing a strange WebView behaviour in my Android app:

when an HTML file containing

<object> 

elements pointing to svg and webm files (for example) is loaded, then the WebView calls shouldOverrideUrlLoading and I see that the old url (getUrl()) is the current file, the new url is the svg/webm content file (for each occurrence).

It does not happen if the content is mp4 or an image.

How to avoid that the WebView is requested to "jump" to the content when object elements are in HTML? Are there other elements, like

<embed> 

for example, that can cause this kind of problems too?

It is needed to catch the body onload event and set some variable to true only after this event is fired; while the variable is false shouldOverrideUrlLoading has to return immediately after call.

To get this, JavaScriptInterface has to be set on the WebView with suitable method, and the body onload event has to be set in the HTML by means of javascript injection when the onProgressChanged method is called with progress==100 or onPageFinished is called.

It worked for me.

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