'how to send multi `windows.postmessage(data)` to a single source, with adding an ID to every message to be able to catch it
I need to send more than one message using js to the same source flutter app
is the source and it is ready to receive all messages based on their ID , which is mentioned in documentations to be sent like this :
measurePointTwo.postMessage(ptTwoData)
this causes the error :
Uncaught ReferenceError: measurePointTwo is not defined
That is because am using measurePointTwo
and I cant not use this because this is how the listener in my flutter
app is getting different messages, based on this ID or unique name.
What I have tried
window.measurePointTwo.postMessage(ptTwoData)
and this is getting me this error :
Uncaught TypeError: Cannot read properties of undefined (reading 'postMessage')
Extra info
- This window runs in my
flutter
app is a Web view
- Inside the
WebView
this function is used to handlepostMessage
:
javascriptChannels: {
JavascriptChannel(
name: 'newCords',
onMessageReceived:
(JavascriptMessage message) {
controller.getLagLngFromJSMessage(
message.message);
}),
JavascriptChannel(
name: 'measurePointOne',
onMessageReceived:
(JavascriptMessage message) {
controller.getPintOneFromJSMessage(
message.message);
}),
JavascriptChannel(
name: 'measurePointTwo',
onMessageReceived:
(JavascriptMessage message) {
controller.getPintTwoFromJSMessage(
message.message);
}),
JavascriptChannel(
name: 'newPoint',
onMessageReceived:
(JavascriptMessage message) {
controller.getClickedPoint(message.message);
}),
},
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|