Home > Web Front-end > JS Tutorial > body text

Detailed explanation of the case analysis of WeChat prohibiting copying link sharing and prohibiting hiding of the menu function in the upper right corner in React Js

黄舟
Release: 2017-05-26 10:14:28
Original
2719 people have browsed it

This article mainly introduces the solution code for React Js WeChat prohibits copying links, sharing, and hiding the menu in the upper right corner. Friends who need it can refer to it

No more nonsense, I will just post the code for you. The specific code is as follows:

/**
 * Created by wuyakun on 2017/5/23.
 */let wxUtils = {};
/**
 * 是否开启右上角Menu
 * @param open
 */
wxUtils.optionMenu = function (open = true) {
 if (open) {
  openOptionMenu();
 } else {
  disabledOptionMenu();
 }
};
/**
 * 是否禁用右上角
 */
function disabledOptionMenu() {
 if (typeof WeixinJSBridge === "undefined") {
  if (document.addEventListener) {
   document.addEventListener('WeixinJSBridgeReady', onBridgeReady(true), false);
  } else if (document.attachEvent) {
   document.attachEvent('WeixinJSBridgeReady', onBridgeReady(true));
   document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(true));
  }
 } else {
  onBridgeReady(true);
 }
}
/**
 * 开启menu
 */
function openOptionMenu() {
 if (typeof WeixinJSBridge === "undefined") {
  if (document.addEventListener) {
   document.addEventListener('WeixinJSBridgeReady', onBridgeReady(false), false);
  } else if (document.attachEvent) {
   document.attachEvent('WeixinJSBridgeReady', onBridgeReady(false));
   document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(false));
  }
 } else {
  onBridgeReady(false);
 }
}
function onBridgeReady(disable = true) {
 if (typeof WeixinJSBridge !== "undefined") WeixinJSBridge.call(disable ? 'hideOptionMenu' : 'showOptionMenu');
}
/**
 * 隐藏微信网页底部的导航栏
 * @param disable
 */
wxUtils.disabledToolbar = function (disable = true) {
 document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
  // 通过下面这个API隐藏底部导航栏
  WeixinJSBridge.call(disable ? 'hideToolbar' : 'showToolbar');
 });
};
/**
 * 获取网络类型
 */
wxUtils.getNetworkType = function () {
 //network_type:wifi wifi网络 2 network_type:edge 非wifi,包含3G/2G 3 network_type:fail 网络断开连接 4 network_type:wwan 2g或者3g
 WeixinJSBridge.invoke('getNetworkType', {}, function (e) {
  // 在这里拿到e.err_msg,这里面就包含了所有的网络类型
  return e;
 });
};
export default wxUtils;
Copy after login

The usage is very simple:

export default class BaseComponent extends React.Component {
 componentDidMount() {
  try {
   //如果存在location说明是路由Component
   if (this.props.location) {
    // 全部禁用分享,想要分享自己开
    wxUtils.optionMenu(false);
   }
  } catch (e) {
   // console.log(e);
  }
 }
}
Copy after login

I wrote it in Base, mainly wxUtils.optionMenu (false);This sentence

The above is the detailed content of Detailed explanation of the case analysis of WeChat prohibiting copying link sharing and prohibiting hiding of the menu function in the upper right corner in React Js. 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!