Usually do a page you want to pass the micro-letter as a friend to share, the title and description of the display is not what they want, I checked some information, the original is through JS to control
The display effect is as follows:
The title, description, and share of the pictures are JS to control.
JS code is as follows
<script> var dataforweixin = {appId: "", Msgimg: "Christmas/201012189457639.gif",//Show picture tlimg: "Christmas/2
01012189457639.gif ",//Display picture URL:" christmas/6.html?stra=!u738b!u4f1f ",///Jump Address title:" Will my thoughts and blessings to you, the source of my wish you a Merry Christmas ",//title content
Desc: "Will my thoughts and blessings to you, the source wish you a Merry Christmas",//description content Fakeid: "", Callback:function () {}}; (function () {var onbridgeready = function () {Weixinjsbridge.on (' menu:share:appmessage ', function (argv) {Weixi Njsbridge.invoke (' Sendappmessage ', {"AppID": Dataforweixin.appid, "Img_url": dataforweixin.msgimg, "Img_width": "", "Img_height": "The", "link": Dataforweixin.url, "desc": Dataforweixin.desc, "title": Dataforweixin.titl
e}, function (res) {(dataforweixin.callback) ();});
});
Weixinjsbridge.on (' Menu:share:timeline ', function (argv) {(dataforweixin.callback) ();
Weixinjsbridge.invoke (' Sharetimeline ', {"Img_url": dataforweixin.tlimg, "img_width": "The", "Img_height": "120", "Link": Dataforweixin.URL, "desc": Dataforweixin.desc, "title": Dataforweixin.title}, Function (res) {});
}); Weixinjsbridge.on (' Menu:share:weibo ', function (argv) {weixinjsbridge.invoke (' Shareweibo ', {"content '): Dataforweix
In.title, "url": Dataforweixin.url}, Function (res) {(dataforweixin.callback) ();});
});
Weixinjsbridge.on (' Menu:share:facebook ', function (argv) {(dataforweixin.callback) (); Weixinjsbridge.invoke (' Sharefb ', {"Img_url": dataforweixin.tlimg, "img_width": "The", "Img_height": "The", "L
Ink ": Dataforweixin.url," desc ": Dataforweixin.desc," title ": Dataforweixin.title}, Function (res) {});
});
};
if (Document.addeventlistener) {document.addeventlistener (' Weixinjsbridgeready ', Onbridgeready, false);
else if (document.attachevent) {document.attachevent (' Weixinjsbridgeready ', onbridgeready);
Document.attachevent (' Onweixinjsbridgeready ', onbridgeready);
}
})(); </script>
Another micro-letter share JS code:
/**! * Micro-letter built-in browser JavaScript API, features include: * * 1, share to micro-trust friend Circle * 2, share to micro-trust friends * 3, share to Tencent micro-blog * 4, new sharing interface, including Friends Circle, friends, microblogging share (for IOS) * 5, hide/show on the right Corner Menu Entrance * 6, hide/Show bottom browser toolbar * 7, get current network status * 8, adjust the micro-letter client's picture playback component * 9, close the Public Platform Web page/var Weixinapi = (function () {"Use St"
Rict "; /** * Share to the micro-trust friend Circle * @param {Object} data to share information * @p-config {string} appId Public platform AppId (service number available) * @p-config {string} imgurl Picture Address * @p-config {string} link URL * @p-config {string} desc Description * @p-config {string} title share titles * * @param {Object} Callbacks Correlation Callback method * @p-config {Boolean} Async Ready method requires asynchronous execution, default false * @p-config {Function} ready (argv) Ready state * @p-c onfig {function} dataloaded (data) is called after loading, Async is true, or it can be null * @p-config {function} cancel (resp) cancel * @p-config {Func tion} fail (RESP) failed * @p-config {function} confirm (RESP) succeeded * @p-config {function} all (RESP) callback/function executed regardless of success failure Weixinsharetimeline (data, callbacks) {callbacks = Callbacks | |
{}; var sharetimeline = function (thedata) {weixinjsbridge.iNvoke (' Sharetimeline ', {"AppID": Thedata.appid? Thedata.appid: ", Img_url": Thedata.imgurl, "link": Thedata.link, "desc": Thedata.title, "title": Thedata.desc,//Note the content to be shared here is desc "img_width": "640", "Img_height": "640"}, Functi On (RESP) {switch (resp.err_msg) {//Share_timeline:cancel user cancels case ' share_timeline:cancel ': callbacks.cance
L && Callbacks.cancel (resp);
Break Share_timeline:confirm send successful case ' share_timeline:confirm ': Case ' Share_timeline:ok ': callbacks.confirm &&A mp
Callbacks.confirm (RESP);
Break
Share_timeline:fail send failed case ' Share_timeline:fail ': Default:callbacks.fail && callbacks.fail (RESP);
Break
The callback Callbacks.all && Callbacks.all (RESP) that will be executed regardless of success failure;
});
}; Weixinjsbridge.on (' Menu:share:timeline ', function (argv) {if (Callbacks.async && callbacks.ready) {window["_ Wx_loadedcb_ "] = callbacks.dataloaded | |
New Function (); if (window["_wx_loadedcb_"].tostring (). IndexOf ("_wx_loadedcb_") > 0) {window["_wx_loadedcb_"] = new Function ();
} callbacks.dataloaded = function (newdata) {window["_wx_loadedcb_"] (NewData);
Sharetimeline (NewData);
};
Then ready Callbacks.ready && Callbacks.ready (argv);
else {//Ready state Callbacks.ready && Callbacks.ready (argv);
Sharetimeline (data);
}
}); /** * Sent to the micro-letter friend * @param {Object} data to share information * @p-config {string} appId Public platform AppId (service number available) * @p-config {string} IM Gurl Picture Address * @p-config {string} link URL * @p-config {string} desc Description * @p-config {string} title share Title * * @param {Ob Ject} callbacks Associated callback method * @p-config {Boolean} Async Ready method requires asynchronous execution, default false * @p-config {Function} ready (argv) Ready state * Called when @p-config {function} dataloaded (data) is loaded, Async is true, or it can be null * @p-config {function} cancel (RESP) * @p-config {function} fail (RESP) failed * @p-config {function} confirm (RESP) succeeded * @p-config {function} all (RESP) callback to be executed regardless of successful failure * * * fun Ction WeixInsendappmessage (data, callbacks) {callbacks = Callbacks | |
{}; var sendappmessage = function (thedata) {weixinjsbridge.invoke (' sendappmessage ', {"AppID": Thedata.appid? Thedata.ap PId: ', "Img_url": Thedata.imgurl, "link": Thedata.link, "desc": Thedata.desc, "title": Thedata.title, "Img_width" : "640", "Img_height": "640"}, function (RESP) {switch (resp.err_msg) {//Send_app_msg:cancel user cancels case ' send
_app_msg:cancel ': Callbacks.cancel && callbacks.cancel (RESP);
Break Send_app_msg:confirm send successful case ' send_app_msg:confirm ': Case ' Send_app_msg:ok ': callbacks.confirm && CA
Llbacks.confirm (RESP);
Break
Send_app_msg:fail send failed case ' Send_app_msg:fail ': Default:callbacks.fail && callbacks.fail (RESP);
Break
The callback Callbacks.all && Callbacks.all (RESP) that will be executed regardless of success failure;
});
};
Weixinjsbridge.on (' Menu:share:appmessage ', function (argv) {if (Callbacks.async && callbacks.ready) { window["_wx_loadedcb_"] = callbacks.dataloaded | |
New Function ();
if (window["_wx_loadedcb_"].tostring (). IndexOf ("_wx_loadedcb_") > 0) {window["_wx_loadedcb_"] = new Function ();
} callbacks.dataloaded = function (newdata) {window["_wx_loadedcb_"] (NewData);
Sendappmessage (NewData);
};
Then ready Callbacks.ready && Callbacks.ready (argv);
else {//Ready state Callbacks.ready && Callbacks.ready (argv);
Sendappmessage (data);
}
}); /** * Share information to Tencent Weibo * @param {Object} data to be shared * @p-config {string} link Address * @p-config {STRING} desc description * * @par AM {Object} Callbacks related callback method * @p-config {Boolean} Async Ready method requires asynchronous execution, the default false * @p-config {Function} ready (argv) Thread state * @p-config {function} dataloaded (data) is called after loading, Async is true, or null * @p-config {function} cancel (RESP) can be canceled * @p-c Onfig {function} fail (RESP) failed * @p-config {function} confirm (RESP) succeeded * @p-config {function} all (RESP) callback that is executed regardless of successful failure * /function Weixinshareweibo (data,Callbacks) {callbacks = Callbacks | |
{}; var Shareweibo = function (thedata) {weixinjsbridge.invoke (' Shareweibo ', {' content ': Thedata.desc, url: thedata.li NK}, Function (RESP) {switch (resp.err_msg) {//Share_weibo:cancel user cancels case ' share_weibo:cancel ': Callbac
Ks.cancel && Callbacks.cancel (RESP);
Break Share_weibo:confirm send successful case ' share_weibo:confirm ': Case ' Share_weibo:ok ': callbacks.confirm && callb
Acks.confirm (RESP);
Break
Share_weibo:fail send failed case ' Share_weibo:fail ': Default:callbacks.fail && callbacks.fail (RESP);
Break
The callback Callbacks.all && Callbacks.all (RESP) that will be executed regardless of success failure;
});
}; Weixinjsbridge.on (' Menu:share:weibo ', function (argv) {if (Callbacks.async && callbacks.ready) {window[' _wx_ Loadedcb_ "] = callbacks.dataloaded | |
New Function (); if (window["_wx_loadedcb_"].tostring () indexOf ("_wx_loadedcb_") > 0) {window["_wx_loadedcb_"] = new FunctioN ();
} callbacks.dataloaded = function (newdata) {window["_wx_loadedcb_"] (NewData);
Shareweibo (NewData);
};
Then ready Callbacks.ready && Callbacks.ready (argv);
else {//Ready state Callbacks.ready && Callbacks.ready (argv);
Shareweibo (data);
}
}); /** * New Sharing interface * @param {Object} data to share information * @p-config {string} appId Public platform AppId (service number available) * @p-config {string} IMGU RL Picture Address * @p-config {string} link URL * @p-config {string} desc Description * @p-config {string} title share titles * * @param {Obje CT} Callbacks Correlation callback method * @p-config {Boolean} Async Ready method requires asynchronous execution, the default false * @p-config {Function} ready (Argv,shareto)
Thread state * @p-config {function} dataloaded (data) is called after loading, Async is true, or it can be null * @p-config {function} cancel (Resp,shareto) * @p-config {function} fail (Resp,shareto) failed * @p-config {function} confirm (Resp,shareto) succeeded * @p-config {function} al L (Resp,shareto) callback/function Weixingeneralshare (data, callbacks) {callbacks = callbacks, regardless of success failure ||
{};
var generalshare = function (general,thedata) {//If you are sharing a circle of friends, you need to swap title and desc for if (General.shareto = = ' Timeline ') {
var title = Thedata.title; Thedata.title = Thedata.desc | |
Title
Thedata.desc = title; //Share out General.generalshare ({"AppID": Thedata.appid? Thedata.appid: ", Img_url": Thedata.imgurl, "link": t Hedata.link, "desc": Thedata.desc, "title": Thedata.title, "img_width": "640", "Img_height": "640"}, function (resp {switch (RESP.ERR_MSG) {//General_share:cancel user cancels case ' general_share:cancel ': Callbacks.cancel &&am P
Callbacks.cancel (resp, general.shareto);
Break General_share:confirm send successful case ' general_share:confirm ': Case ' General_share:ok ': callbacks.confirm &&
Callbacks.confirm (resp, general.shareto);
Break General_share:fail send failed case ' General_share:fail ': Default:callbacks.fail && callbacks.fail (resp, Gen
Eral.shareto);
Break ///No matter if successful failure will be executed by the callback CAllbacks.all && Callbacks.all (resp, general.shareto);
});
}; Weixinjsbridge.on (' Menu:general:share ', function (general) {if (Callbacks.async && callbacks.ready) {window[ "_wx_loadedcb_"] = callbacks.dataloaded | |
New Function ();
if (window["_wx_loadedcb_"].tostring (). IndexOf ("_wx_loadedcb_") > 0) {window["_wx_loadedcb_"] = new Function ();
} callbacks.dataloaded = function (newdata) {window["_wx_loadedcb_"] (NewData);
Generalshare (General,newdata);
};
Then ready Callbacks.ready && Callbacks.ready (General,general.shareto);
else {//Ready state Callbacks.ready && Callbacks.ready (General,general.shareto);
Generalshare (General,data);
}
}); /** * ATTENTION (this feature is only temporarily added, but because of permissions restrictions, can not be used, if your site is deployed under *.qq.com, may be feasible) * @param {String} Appweixinid micro-public number ID * @param {objec T} Callbacks callback method * @p-config {function} fail (RESP) failed * @p-config {function} confirm (RESP) successful/function Addcontact ( Appweixinid,callbacks) {callbacks = Callbacks | |
{}; Weixinjsbridge.invoke ("Addcontact", {webtype: "1", Username:appweixinid}, function (RESP) {var success =!resp. err_msg | | "Add_contact:ok" = = Resp.err_msg | |
"add_contact:added" = = resp.err_msg;
if (success) {callbacks.success && callbacks.success (RESP);
}else{callbacks.fail && callbacks.fail (RESP);
})}/** * Native the picture playback component of the micro-letter. * Here must be strong detection of parameters, if the parameters are not legitimate, directly lead to the micro-client crash * * @param {String} cursrc currently playing picture address * @param {Array} srclist picture Address list * * * FUNCTI
On Imagepreview (cursrc,srclist) {if (!cursrc | |!srclist | | srclist.length = 0) {return;
} weixinjsbridge.invoke (' Imagepreview ', {' current ': cursrc, ' URLs ': srclist});
/** * Displays the button on the top right corner of the page/function Showoptionmenu () {weixinjsbridge.call (' showoptionmenu ');
/** * Hide the button on the top right corner of the page */function Hideoptionmenu () {weixinjsbridge.call (' hideoptionmenu ');
/** * Displays the bottom toolbar/function ShowToolbar () {weixinjsbridge.call (' ShowToolbar ');
}/** * Hide Bottom Toolbar * *function Hidetoolbar () {weixinjsbridge.call (' Hidetoolbar '); /** * Returns the following types: * Network_type:wifi WiFi network * network_type:edge non-wifi, including 3g/2g * network_type:fail Network Disconnect * NETW
Ork_type:wwan 2g or 3g * * Use Method: * Weixinapi.getnetworktype (function (networktype) {* *});
* * @param callback */function Getnetworktype (callback) {if (callback && typeof callback = ' function ') {
Weixinjsbridge.invoke (' Getnetworktype ', {}, function (e) {//Get e.err_msg here, which includes all network types callback (E.ERR_MSG);
});
}/** * Closes the current micro-credit public Platform page/function CloseWindow () {Weixinjsbridge.call ("CloseWindow");
/** * When the page is loaded and executed, use the method: * Weixinapi.ready (function (API) {*//From here only API is WEIXINAPI *}); * @param readycallback */function Wxjsbridgeready (readycallback) {if (readycallback && typeof readycallback =
= ' function ') {var Api = this;
var wxreadyfunc = function () {readycallback (API);
}; if (typeof window. Weixinjsbridge = = "undefined") {if (document. AddEventListener) {document.addeventlistener (' Weixinjsbridgeready ', Wxreadyfunc, false);
else if (document.attachevent) {document.attachevent (' Weixinjsbridgeready ', wxreadyfunc);
Document.attachevent (' Onweixinjsbridgeready ', wxreadyfunc);
}}else{Wxreadyfunc (); }} return {version: "2.0", Ready:wxjsbridgeready, Sharetotimeline:weixinsharetimeline, Sharetoweibo:weixi Nshareweibo, Sharetofriend:weixinsendappmessage, Generalshare:weixingeneralshare, Addcontact:addcontact, ShowOptio Nmenu:showoptionmenu, Hideoptionmenu:hideoptionmenu, Showtoolbar:showtoolbar, Hidetoolbar:hidetoolbar, GetNetworkT
Ype:getnetworktype, Imagepreview:imagepreview, Closewindow:closewindow};
})();
This article has been organized into the "JavaScript micro-Credit Development Skills Summary", welcome to learn to read.
For everyone to recommend now more attention than the micro-letter Program Tutorial: "Micro-letter Small Program Development tutorial" Small series for everyone carefully organized, hope like.
The above is a micro-letter to share the JS code, I hope to help you learn.