Developing app apps is a little less challenging than developing mobile Web pages, because apps only need to fit different phones, and mobile pages not only need to fit on different phones, but also with different browsers for the same phone.
Mobile page sharing is a common feature that requires a hosting environment, can be an app, or it can be a browser.
If the HTML page is embedded in the app or if you want to share the function, you need to add code on the button element, either invoke the app method or protocol, or call the API, or if the HTML page opens directly in the browser, the front end of the page does not have to be shared, as the browser comes with the share.
From the perspective of the front page, the following details about sharing and app sharing and browser sharing.
First, share
Description: Mobile HTML page embedding, call sharing function.
Official document:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115
1. Package JS
Require.async ('/static/common/wxshare/jweixin-1.0.0.js ',function() {wx.config ({debug:false,//turn on debug mode, call the return value of all the APIs will be on the client alert, to see the incoming parameters can be opened on the PC side, the parameter information will be typed through log, only on the PC side will be printed. AppId:wxParamObj.appId,//mandatory, unique identification of the public numberTimestamp:wxParamObj.timestamp,//required, time stamp for signature generationNONCESTR:WXPARAMOBJ.NONCESTR,//required, generate a random string of signaturesSignature:wxParamObj.signature,//Required, Signaturejsapilist: ["Onmenushareappmessage", "Onmenusharetimeline" ] //Required , the list of JS interfaces to use }); Wx.ready (function(){ /** * Config information validation will execute the Ready method, all interface calls must be obtained after the Config interface results, * config is a client's asynchronous operation, so if you need to call the interface when the page loads, * The relevant interface must be placed in the RE The Ady function is called to ensure proper execution. */ //share to a circle of friendsWx.onmenusharetimeline ({title:wxParamObj.title,//Share titleLink:wxParamObj.link,//Share LinksIMGURL:WXPARAMOBJ.IMGURL,//Share iconSuccessfunction () { //callback function that is executed after the user confirms the share}, Cancel:function () { //callback functions executed after the user cancels the share } }); //Share to FriendsWx.onmenushareappmessage ({title:wxParamObj.title,//Share titleDesc:wxParamObj.desc,//Share DescriptionLink:wxParamObj.link,//Share LinksIMGURL:WXPARAMOBJ.IMGURL,//Share iconType: ',//share type, music, video or link, do not fill in the default linkDataurl: ",//if type is music or video, provide a data link, default is nullSuccessfunction () { //callback function that is executed after the user confirms the share}, Cancel:function () { //callback functions executed after the user cancels the share } }); });});
2, Transmission parameters
var wxparamobj = {// define global variable debug: "<?php echo $debug;? > ", " <?php echo $appId;? > ", " <?php echo $timestamp;? > ", " <?php echo $nonceStr;? > ", " <?php echo $signature;? > ", " <?php echo $title;? > ", " <?php echo $desc;? > ", " <?php echo $link;? > ", " <?php echo $imgUrl;? > "}
The button to share is the element of the native page, the front page of the webpage just passes parameters, and the app listens for click events.
Second, app sharing
Description: Mobile HTML page embedded app, call app native sharing function.
Scenario 1:
The shared button is the element of the app's native page. Web page front-end data transfer app customization method, the app front-end monitoring Click events, pop-up sharing box. The following code executes when the HTML page is initialized.
var wxparamobj = { title:title, // share title desc:content, // Share Description imgurl:imgurl, // share icon shareurl:link // Share Links = json.stringify (wxparamobj);p ahaofang.setrightitem (' share ', wxparamobjstr);
Scenario 2:
The shared button is an element of the HTML page. Web front-end monitoring click events, pass parameters, adjust the app method. When you click on an HTML element, the following code executes. (The front end of the Web page writes the following code in the Click event)
Native.share (title, Content, link, imgurl);
Scenario 3:
The shared button is an element of the HTML page. The Web front-end listens for click events and redirects to the app protocol. When you click on an HTML element, the following code executes. (The front end of the Web page writes the following code in the Click event)
<href= "javascript:void (0);" class = "Hft-share" > share </a>
var shareurl = "haofangtuo://service/showsnspad?desc= hoe wo day copse \ r \ n" Information content content content! & "+" imgurl=http://static.xxx.com/mmm.png& "+" shareurl= "+encodeuricomponent (link) +" &title= hoe wo Day copse \r\ N content content of information and information contents "; $ (function(event) {= shareurl;});
Third, browser sharing
The browser comes with the share function, the mobile HTML page does not have to do extra.
Mobile HTML page Sharing