How to add a Public Account link to a website
Here, the free spread of Public Accounts refers to spreading your public accounts to friends and friends. After a friend clicks in, he can follow your public accounts in the shortest path! If your article is pushed through the background of the public platform, you will find that the corresponding public account nickname can be clicked, And you can directly open the public account information page. Let's take a look at its source code:
HTML code:
Baidufe
Javascript code:
Function viewProfile (){
If (typeof WeixinJSBridge! = "Undefined" & WeixinJSBridge. invoke ){
WeixinJSBridge. invoke ('profile ',{
'Username': 'gh _ dd4b2c2ada8b ',/* original ID of your public account */
'Scene': '57'
});
}
}
You may be glad to think that this code has taken effect!
In fact, this Code takes effect only in the mp.weixin.qq.com domain in the iOS environment!
Of course, you can doubt that, next we can make a simple modification to the above Javascript code to see what information will be obtained in callback:
Function viewProfile (){
If (typeof WeixinJSBridge! = "Undefined" & WeixinJSBridge. invoke ){
WeixinJSBridge. invoke ('profile ',{
'Username': 'gh _ dd4b2c2ada8b ',/* original ID of your public account */
'Scene': '57'
}, Function (resp ){
Alert (resp. err_msg);/* here, We output err_msg */
});
}
}
We deploy the code to our own web server, such as: http://www.baidufe.com/demo/wxid_test.html, then open this link with a built-in browser, click the tag defined in HTML, call the viewProfile method, the "not_allow" error message is displayed!
How can this problem be solved? Is there really no way to easily spread public accounts on your own pages?
In fact, we can look around it like this:
1. Push the simplest text message through the background of the public platform, which generates an independent page. on this page, you can click the nickname to open the public account information page. For example, this Demo independent page
2. Add a link on our own page to point to the independent page generated above
The independent page is similar:
Of course, all discussed above are for the iPhone version. Indeed, the WebView on iOS is much more restrictive than the WebView on Android.
Next, let's take a look at how to promote the public account on Android & WP.
In fact, it is very simple (I wrote it in my previous Blog), it is done by a link:
Click here to add the Baidufe public account
Above, you can spread the public account freely on your page!