Home > Article > Backend Development > Instance method that restricts web pages to be opened only in WeChat's built-in browser
Regarding the difference between the two scopes of web page authorization, this article mainly shares with you the example method of restricting web pages to be opened only in the built-in browser of WeChat. I hope it can help everyone.
List content
2.
<script type="text/javascript"> // 对浏览器的UserAgent进行正则匹配,不含有微信独有标识的则为其他浏览器 var useragent = navigator.userAgent; if (useragent.match(/MicroMessenger/i) != 'MicroMessenger') { // 这里警告框会阻塞当前页面继续加载 alert('已禁止本次访问:您必须使用微信内置浏览器访问本页面!'); // 以下代码是用javascript强行关闭当前页面 var opened = window.open('about:blank', '_self'); opened.opener = null; opened.close(); } </script>rrree
Related recommendations:
PHP restricts web pages to only be viewed and displayed in WeChat’s built-in browser_PHP tutorial
The above is the detailed content of Instance method that restricts web pages to be opened only in WeChat's built-in browser. For more information, please follow other related articles on the PHP Chinese website!