Home  >  Article  >  Backend Development  >  Instance method that restricts web pages to be opened only in WeChat’s built-in browser

Instance method that restricts web pages to be opened only in WeChat’s built-in browser

小云云
小云云Original
2018-03-08 14:51:375094browse

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.

  1. List content

  2. 2.

 <script type="text/javascript">
     // 对浏览器的UserAgent进行正则匹配,不含有微信独有标识的则为其他浏览器
     var useragent = navigator.userAgent;     if (useragent.match(/MicroMessenger/i) != &#39;MicroMessenger&#39;) {         // 这里警告框会阻塞当前页面继续加载
         alert(&#39;已禁止本次访问:您必须使用微信内置浏览器访问本页面!&#39;);         // 以下代码是用javascript强行关闭当前页面
         var opened = window.open(&#39;about:blank&#39;, &#39;_self&#39;);
         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!

Statement:
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