Error When Web Components Send a Message to an HTML5 Page

As I am developing huawei quick app,When Web Components send a message to an HTML5 page, the following JS error is reported: 02–14 09:22:56.329 E/jsLog (18834): [H5]Uncaught TypeError: system.onmessage is not a function how can I solve it?

1 answer

  • answered 2021-04-14 03:48 shirley

    Ensure that the system.onmessage function in the HTML5 page only contains the necessary logic, that is, receiving data transmitted from a quick app page. You can leave other logic, for example, handling onload events, to lifecyle functions of the HTML5 page for processing. Note that data from the quick app is not received once the onload event is triggered. In this case, the HTML5 page needs to listen to data receiving in polling mode. To achieve this, refer to the following sample code.

    enter image description here

    The following code is not recommended.

    enter image description here

    You should understand the mechanism for sending messages between a quick app and an HTML5 page. Then use the polling mode to solve the asynchronous data transmission problem.