關於微信端分享頁面的設定問題
阿新 • • 發佈:2019-02-10
一、
//js介面
var shareme;
var urls = window.location.href;if(isWeiXin()){
var weifileref=document.createElement('script')//建立標籤
weifileref.setAttribute("type","text/javascript")//定義屬性type的值為text/javascript
weifileref.setAttribute("src", "http://res.wx.qq.com/open/js/jweixin-1.0.0.js")//檔案的地址
document.getElementsByTagName("head")[0].appendChild(weifileref);
}
function isWeiXin(){
var ua = window.navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == 'micromessenger'){
return true;
}else{
return false;
}
}
//修改jq
$(window).load(function(){
if(isWeiXin()){
$.ajax({
type: "POST",
async: false, //同步請求
url: "",
data:{
urls:urls
},
jsonp: 'callback',
dataType: 'jsonp',
success:function(data){
shareme = eval(data);
wx.config({
debug: false,
appId: shareme.appId,
timestamp: shareme.timestamp,
nonceStr: shareme.nonceStr,
signature: shareme.signature,
jsApiList: [
// 所有要呼叫的 API 都要加到這個列表中
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'hideMenuItems',
'showMenuItems',
'hideAllNonBaseMenuItem',
'showAllNonBaseMenuItem'
]
});
wx.ready(function () {
//判斷當前版本是否支援指定 JS 介面,支援批量判斷
wx.checkJsApi({
jsApiList: [
'getNetworkType',
'previewImage',
'onMenuShareTimeline',
'onMenuShareAppMessage'
],
success: function (res) {
},
fail:function(){
alert('抱歉您的微信版本有問題不支援分享功能!');
}
});
//分享介面
//監聽“分享給朋友”
wx.onMenuShareAppMessage({
title: '速途網路熱招崗位',
desc: '速途網路感謝您的關注!',
link: 'http:/',
imgUrl: /share.png',
trigger: function (res) {
//alert('使用者點擊發送給朋友');
},
success: function (res) {
//alert('已分享');
},
cancel: function (res) {
//alert('已取消');
},
fail: function (res) {
//alert(JSON.stringify(res));
}
});
// 監聽“分享到朋友圈”按鈕點選
wx.onMenuShareTimeline({
title: '速途網路熱招崗位',
desc: '速途網路感謝您的關注!',
link: 'http://',
imgUrl: '/share.png',
trigger: function (res) {
//alert('使用者點選分享到朋友圈');
},
success: function (res) {
//alert('已分享');
},
cancel: function (res) {
//alert('已取消');
},
fail: function (res) {
// alert(JSON.stringify(res));
}
});
});
wx.error(function (res) {
//alert(res.errMsg);
});
},
error: function () {
}
});
}else{
//alert("對不起您不在微信瀏覽器中,不支援分享功能!");
return false;
}
});
//不過不知道為什麼,試了半天這個方法我一直沒有效果,好像介面連結不太對
二、
head裡的title就是分享的問題
分享的圖片,一般就是每頁的body裡面的第一張圖片,300*300以上才行;
可以寫個div,包含想要的img,然後設定div隱藏,img隱藏的話實現不了。