Can anyone please help me on how to detect Webview button click event in React Native? As shown in the code below, I have a Button in my WebView (index.html) for which i wan
Add window.postMessage()
to your page file and onMessage={this.onMessage}
to your React Native WebView component.
Example:
// index.html (Web)
...
...
// MyWebView.js (React Native)
...
onMessage(data) {
//Prints out data that was passed.
console.log(data);
}
Edit: Working example:
App.js
onMessage(m) {
alert(m.nativeEvent.data);
}
render() {
return(
this.onMessage(m)}
/>
);
}
index.html
Hope it helps