This article is a mirror article of machine translation, please click here to jump to the original article.

View: 1164|Reply: 1

WeChat mini program shares the H5 page in WebView

[Copy link]
Posted on 2025-2-20 08:52:38 | | | |
Requirements: When using WebView nested in the WeChat mini program, when you need to click to share with friends or circle of friends, the user clicks on the shared card to enter the display H5 page.

First, let's take a look at the renderings shared into the chat:



Principle: The H5 page sends a message to the mini program, and the mini program clicks to share to read the message, as shown in the figure below:

bindmessage eventhandler No When a web page sends a postMessage to the mini program, it will trigger and receive a message at the following specific times: the mini program is backtracked, the component is destroyed, shared, and the link is copied (2.31.1). e.detail = { data }, data is an array of parameters that have been posted multiple times.

wx.miniProgram.postMessage sends a message to the mini program, which triggers the component's message event at the following specific times: mini program back, component destruction, sharing, copy link (2.31.1)



web-view:The hyperlink login is visible.

H5 page

The H5 page uses postMessage to send a message to the applet, and the code is as follows:

WeChat mini program

The code is as follows:

Note: What is shared is still the mini program page path, but the parameter link of the h5 page must be attached to the path.

onShareAppMessage: Used when sharing with friends or group chats.
onShareTimeline: Used to configure when sharing to Moments.

Procedure:

The operation steps are as follows:





Previous:.NET/C# uses HttpClient common request trick methods
Next:RMSE, MSE, MAE, SD brief introduction
 Landlord| Posted on 2025-2-20 09:01:22 |
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com