简体   繁体   中英

Load HTML file into WebView that contain external js script

I want to load a html code into a webview. But the html code has several other external resources. for example in the html code I have :

<script type="text/javascript" src="//cdn3.example.com/example.js"></script>

but it seems that 'example.js' is not executed when rendering the webview.

Is it possible to achieve that ? Thank you

I have similar issue, webview loaded from file:// and won't load external resources... cors set to * on the server side too.

So digging into it further, seems my problem was I used custom ssl certs on server side and android couldn't verify the server authenticity, and so requests were being cancelled. (adding intermediate certs to app would help)

alternately You can override webclient's shouldInterceptRequest and fetch the external scripts yourself, returning the request from which webview will draw data (make sure you don't fetch during the shouldInterceptRequest call or it will be slooooooow sequentially fetching resources; instead, return a request's subclass and start fetching data async, so by time call to getData comes you already have what you need... search so for async shouldInterceptRequest for help with that).

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