How to send post message from webview
Introduction
In this guide, we will learn how to send a post message from a webview.
How to send post message from webview
To send a post message, use the following code:
window.ReactNativeWebView.postMessage("my-message");
To receive this message, apply the following filter:
appmaker.addFilter(
'appmaker-webview-message-data',
'myCustomFilter', // Replace with your extension id
myCustomFilterHandler, // Replace with your custom filter handler function
);
export function myCustomFilterHandler(data, { event, url }) {
// Handle the data received from the post message
console.log(`Custom webview event data`, data, url);
// Add your custom logic here
if (url.includes('yourdomain.com')) {
// Do something
}
return data;
}