微信h5开发,记得设置jssdk安全域名。服务一定要是https协议的,下面是贴出代码
重点分享时网址一定要与安全域名一样, 可带参数,但是#号的分享链接是不能用到的,需要自己起一个静态页面,跳转,如下
let url = encodeURIComponent('https://www.url.com#/?id=10')
wx.onMenuShareTimeline({
title:title,
desc:desc,
link: `https://www.url.com/static/restart.html?page=${url}`,
imgUrl: imgurl,
success: function(){
console.log('朋友圈分享');
}
});
restart.html 代码
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>社会招聘</title>
</head>
<body>
<script>
function GetRequest() {
var url = decodeURI(location.search); //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for ( var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
var item = GetRequest()
if(item['page']){
window.location.href =item['page']
}
</script>
</body>
</html>