背景
小程序開發(fā)避免不了要和h5交互,怎么和h5互通信息呢?文章來源:http://www.zghlxwxcb.cn/news/detail-657515.html
代碼
1、h5頁面手動引入 https://appx/web-view.min.js
(此鏈接僅支持在支付寶客戶端內(nèi)訪問);文章來源地址http://www.zghlxwxcb.cn/news/detail-657515.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>認(rèn)證跳轉(zhuǎn)</title>
</head>
<body>
<!-- 如該 H5 頁面需要同時在非支付寶客戶端內(nèi)使用,為避免該請求404,可參考以下寫法 -->
<!-- 請盡量在 html 頭部執(zhí)行以下腳本 -->
<script>
if (navigator.userAgent.indexOf('AlipayClient') > -1) {
document.writeln('<script src="https://appx/web-view.min.js"' + '>' + '<' + '/' + 'script>');
}
</script>
<script>
my.redirectTo({url: '/pages/certificationTransfer/certificationTransfer?pageName=supplierTwo&certificationType=法人'});
// 網(wǎng)頁向小程序 postMessage 消息
my.postMessage({name:"認(rèn)證跳轉(zhuǎn)"});
// 接收來自小程序的消息。
my.onMessage = function(e) {
console.log(e); // {'sendToWebView': '1'}
}
// 判斷是否運行在小程序環(huán)境里
my.getEnv(function(res) {
console.log(res.miniprogram) // true
});
my.startShare();
</script>
</body>
</html>
到了這里,關(guān)于支付寶小程序內(nèi)嵌H5——支付寶小程序webview里面h5跳回道支付寶小程序頁面的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!