(React Native) Load local HTML file into WebView
try it:
const PolicyHTML = require('./Policy.html');
<WebView
source={PolicyHTML}
style={{flex: 1}}
/>
How to load a local html file into a NativeScript webview
In NativeScript, by default, the tilde (~
) marks the app root folder (note the App and not the Project!). So if your file is located in <project-name>/app/index.html
try setting the path with ~/index.html
.
Can't load a local html file into a .NET MAUI WebView
I've fixed this with this PR into .Net Maui. Will be in the SR2 release due in the next few weeks.
The docs suggested it worked consistently on all platforms, but it simply had never been implemented on Windows... slightly concerning.
The workaround I've posted on the PR (mentioned also by Reinaldo below) will get around this for the mean time, however you should probably remove it once SR2 is released and you update to it.
Add Local HTML and JS file using React Native Webview
<View
style={{
flex:1
}}
>
<WebView
scalesPageToFit
originWhitelist={["*"]}
source={{ uri:"file:///android_asset/highcharts/index.htm",baseUrl:"file:///android_asset/highcharts/"
}}/>
</View>
Here is a working example of highchart in react-native-webview
.
- 1.First move all your
html/js
code to the following directory:your_project/android/app/src/main/assets/
. If theassets
folder does not exist already, create it. - Now paste all your
html/css/js
code in theassets
folder you have created - close your terminal/cmd/bash or whatever you use to run
react-native run-android
command. - Run the following command now.
react-native run-android
. Now paste the above code in your
.js
file. Seturi
to the path to your html file such asuri:"file:///android_asset/YOUR_HTML_FILE"
and yourbaseUrl:"file:///android_asset/YOUR_MAIN_FOLDER/"
WebView2 how to load local file?
You can read HTML file , and then NavigateToString
if (webView!= null && webView.CoreWebView2 != null)
{
string text = system.IO.File.ReadAllText(@"C:/Users/xxx/Desktop/VisualSelf/self.html");
webView.CoreWebView2.NavigateToString(text);
}
or you can Navigate
to local file:
webView.CoreWebView2.Navigate("file:///C:/Users/xxx/Desktop/VisualSelf/self.html");
Also, you need to install Microsoft Edge WebView2 Runtime.
Related Topics
Android Emulator Screen Fills Up Only Some Fraction Part of Actual Android Emulator Screen
How to Resize a Android Webview After Adding Data in It
Display Toolbar for Google Maps Marker Automatically
Swiperefreshlayout + Webview When Scroll Position Is at Top
How to Send Location of the Device on Server When Needed
Android:Record Sound in Mp3 Format
Android Class Parcelable with Arraylist
Xml Rendering Errors Android Preview N
How to Change Action Bar Actions Dynamically
Asynctask, Must It Take Such a Performance Penalty Hit...
Creating a Dialogpreference from Xml
Communicating with Serial Usb Device Over Android
Using the New "Manifestmerger" Property in Android