WeChat public account development implements sample code to return to the chat interface by clicking the return button

高洛峰
Release: 2017-03-13 14:04:48
Original
3516 people have browsed it

This article shares the sample code for WeChat public account development to return to the chat interface by clicking the return button. Friends who need it, let’s take a look together

Without further ado, please take a look at the code

pushHistory();
function pushHistory() {
 var state = {
  title: "title",
  url: "#"
 };
 window.history.pushState(state, "title", "#");
}
if (typeof window.addEventListener != "undefined") {
 window.addEventListener("popstate", function (e) {
 WeixinJSBridge.call('closeWindow');
 }, false);
} else {
 window.attachEvent("popstate", function (e) {
 WeixinJSBridge.call('closeWindow');
 });
}
 pushHistory();
 function pushHistory() {
  var state = {
  title: "title",
  url: "#"
  };
  window.history.pushState(state, "title", "#");
 }
 $(function() {
  wx.config({
  debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  appId: '@ViewBag.AppID', // 必填,公众号的唯一标识
  timestamp: '@ViewBag.TimeStamp', // 必填,生成签名的时间戳
  nonceStr: '@ViewBag.NonceStr', // 必填,生成签名的随机串
  signature: '@ViewBag.Signature', // 必填,签名,见附录1
  jsApiList: [
   'checkJsApi',
   'hideOptionMenu',
   'scanQRCode',
   'closeWindow'
   ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  });
  wx.ready(function() {
  wx.hideOptionMenu();
  });
  if (typeof window.addEventListener != "undefined") {
  window.addEventListener("popstate", function(e) {
   wx.closeWindow();
  }, false);
  } else {
  window.attachEvent("popstate", function(e) {
   wx.closeWindow();
  });
  }
 });
Copy after login


The above is the detailed content of WeChat public account development implements sample code to return to the chat interface by clicking the return button. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!