I load a local html file (from assets folder) to the app WebView.
In the HTML I run a jQuery.getJSON(url). the url is a remote server.
This action fails, and I’m guessing because of a different origin issue (cross domain). I run the same file on chrome and there it specifically says so.
On the following reference [2] you can find a short and clear revision of the problem of displaying local images in a UIWebView using CSS. To use relative paths or files in UIWebView, you have to load the HTML into the view with the correct base URL parameter. The following example shows how to do this. Search for jobs related to Uiwebview local javascript file or hire on the world's largest freelancing marketplace with 15m+ jobs. It's free to sign up and bid on jobs. Search for jobs related to Uiwebview local javascript file or hire on the world's largest freelancing marketplace with 15m+ jobs. It's free to sign up and bid on jobs.
Is there a way to allow the WebView in Android to load data from remote server on a local loaded HTML file?
Today morning I found solution that seems to be working.
Initialize your WebView:
get WebView settings:
set following settings:
now you can load your your html file by standard way:
Create XHR request by standard way
Print the result somewhere
NOTICE:
This procedure works only on API level 16 or higher (At least the documentation says that).
Don’t forget to add the internet permission in your manifest file:
Also make sure you are using JSONP requests (don’t forget the &callback=? as stated above)
I load a local html file (from assets folder) to the app WebView
Note that you failed to say how you are doing this. I am going to guess that it was by a loadUrl()
on a file:///android_asset
URL.
Is there a way to allow the WebView in Android to load data from remote server on a local loaded HTML file?
Try using loadDataWithBaseURL()
to load the content, supplying a URL on the remote server as the base URL.
Ajax calls wont work from local file system. More over it will become cross-domain. So it wont work. It worked in eclipse, becuz you tried from local server.
A solution we used was to use Android to get the update files from the server, place them and overwrite files in the web folder, and then browse.
Tags: dom, file, html, java, javascript, view, webview
I load a local html file (from assets folder) to the app WebView.
In the HTML I run a jQuery.getJSON(url). the url is a remote server.
This action fails, and I’m guessing because of a different origin issue (cross domain). I run the same file on chrome and there it specifically says so.
Is there a way to allow the WebView in Android to load data from remote server on a local loaded HTML file?
Today morning I found solution that seems to be working.
Initialize your WebView:
get WebView settings:
set following settings:
now you can load your your html file by standard way:
Create XHR request by standard way
Print the result somewhere
NOTICE:
This procedure works only on API level 16 or higher (At least the documentation says that).
Don’t forget to add the internet permission in your manifest file:
Also make sure you are using JSONP requests (don’t forget the &callback=? as stated above)
Uiwebview Local Html Javascript Files
I load a local html file (from assets folder) to the app WebView
Note that you failed to say how you are doing this. I am going to guess that it was by a loadUrl()
on a file:///android_asset
URL.
Is there a way to allow the WebView in Android to load data from remote server on a local loaded HTML file?
Try using loadDataWithBaseURL()
to load the content, supplying a URL on the remote server as the base URL.
Javascript In Html
Ajax calls wont work from local file system. More over it will become cross-domain. So it wont work. It worked in eclipse, becuz you tried from local server.
A solution we used was to use Android to get the update files from the server, place them and overwrite files in the web folder, and then browse.
Javascript Local File Path
Tags: dom, file, html, java, javascript, view, webview