-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
33 lines (30 loc) · 1.07 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html>
<head>
<title>H5 Page</title>
<script src="https://unpkg.com/plus-webview-js@latest/dist/plus-webview-js.min.js"></script>
</head>
<body>
<button onclick="sendMessage()">Send Message to UniApp</button>
<script>
function sendMessage() {
// 使用 evalJS 方式发送消息
if (window.plus && window.plus.webview) {
var parentWebview = plus.webview.currentWebview().parent();
parentWebview.evalJS('handleMessageFromH5("Hello from H5!")');
}
// 或者使用 postMessage 方式发送消息
if (window.parent && window.parent.postMessage) {
window.parent.postMessage({
type: 'message',
data: 'Hello from H5 using postMessage!'
}, '*');
}
}
// 处理来自 UniApp 的消息(可选)
window.addEventListener('message', function(event) {
console.log('Received message from UniApp: ', event.data);
});
</script>
</body>
</html>