设置html网页只能在微信中打开,并禁用分享功能
作者:互联网
设置html网页只能在微信中打开,并禁用分享功能
(function () {
/* begin禁用微信分享功能 */
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();
}
/* end禁用微信分享功能 */
// 对浏览器的UserAgent进行正则匹配,不含有微信独有标识的则为其他浏览器
var useragent = navigator.userAgent;
if (useragent.match(/MicroMessenger/i) != 'MicroMessenger') {
// 这里警告框会阻塞当前页面继续加载
// 以下代码是用javascript强行关闭当前页面
var opened = window.open('about:blank', '_self');
/*opened.opener = null;
opened.close();*/
}
else{
window.alert = function(name){
var iframe = document.createElement("IFRAME");
iframe.style.display="none";
iframe.setAttribute("src", 'data:text/plain,');
document.documentElement.appendChild(iframe);
window.frames[0].window.alert(name);
iframe.parentNode.removeChild(iframe);
}
}
})
https://blog.csdn.net/u013176571/article/details/71081230/
标签:网页,微信,window,html,onBridgeReady,iframe,禁用,document 来源: https://blog.csdn.net/weixin_49295874/article/details/114581071