1、屏蔽公众号的复制分享功能
$(function(){
function onBridgeReady() {
WeixinJSBridge.call('hideOptionMenu');
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
}
} else {
onBridgeReady();
}
});
2、JS限制H5页面只能在手机微信中打开JS限制H5页面只能在手机微信中打开
<script type="text/javascript">
var str = "本页面禁止PC端使用,请在手机微信客户端操作。";
function checkPlatform(){
//禁止网站F12
document.onkeydown = function(){
if(window.event && window.event.keyCode == 123) {
alert("F12被禁用");
event.keyCode=0;
event.returnValue=false;
}
if(window.event && window.event.keyCode == 13) {
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 8) {
alert(str+"\n请使用Del键进行字符的删除操作!");
window.event.returnValue=false;
}
}
var u = navigator.userAgent;
//ios终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
//android终端
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
if(/MicroMessenger/i.test(navigator.userAgent)){
var is_mobi = navigator.userAgent.toLowerCase().match(/(ipod|ipad|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null;
if (is_mobi) {
if(isiOS){
//判断是不是ios10系统
var ver = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
ver = parseInt(ver[1], 10);
if(ver<10) {
str = '您当前手机的系统版本不支持,请在IOS10及以上版本操作';
showforbidpage();
} else {
//可以继续操作
}
}
}else{
str = '请在手机微信客户端打开链接';
showforbidpage();
}
}else {
str = '请在手机微信客户端打开链接';
showforbidpage();s
}
}
function showforbidpage(){
window.stop();
var img = '<img style="width:100px; height:100px" src="http://l087-prod.oss-cn-szfinance.aliyuncs.com/lmes_new/dev/h5_image/chahao.png">';
var div = '<div><div style="padding-top: 20px;text-align: center;">'+img+'</div><div style="padding-top: 20px;text-align: center;"><h4>'+str+'</h4></div></div>';
$("body").html(div);
}
$(document).ready(function(){
checkPlatform();
});
</script>
3、微信官方文档有介绍如何屏蔽分享功能
function onBridgeReady() {
WeixinJSBridge.call('hideOptionMenu');
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
}
} else {
onBridgeReady();
}