react-native-webview-android
react-native-webview-android copied to clipboard
How do I receive a message sent by a webview in an html file when I load html?
How do I receive a message sent by a webview in an html file when I load html?
The official webview is using document.addEventListener('message', function (e) {}
Hi @xpbtmusic
If you need just sent a data when your html file load, you could use the prop injectedJavaScript
instead.
Something like:
return (
<WebViewAndroid
ref="webViewAndroidSample"
javaScriptEnabled={true}
injectedJavaScript={`window.myMessageToRecover = 'Hello from React Native';`}
url={"https://yourwebsite.com"}
style={{ flex: 1 }} />
);
And then, in your HTML you could recover the variable window.myMessageToRecover
in on page ready or in your page load events.