博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用js检测用户是否在用微信浏览器浏览网站
阅读量:6927 次
发布时间:2019-06-27

本文共 1324 字,大约阅读时间需要 4 分钟。

  现在大部分的公司喜欢把自己发布的网址转成二维码,然后用户只要用手机扫一下就能登录。而大部分的用户都喜欢(可能不知道还有其他扫码工具)用微信来扫二维码,大家都知道微信里面自带的浏览器会屏蔽大部分的外部网站,只能点击右上角图标,然后“点击在浏览器中打开”才行。所以我们需要就要采取一些措施为了防止我们的网站在用户用微信浏览器打开时被屏蔽,而导致用户不知道该怎么办(大部分的人都不知道)。

  下面是判断用户是否在用微信浏览器的js

// 是否是微信浏览器function is_weixin() {    var ua = navigator.userAgent.toLowerCase();    return ua.match(/MicroMessenger/i) == "micromessenger" ? true : false }// 加载提示图片function loadHtml() {    var div = document.createElement('div');    div.id = 'weixin-tip';    div.innerHTML = '

微信打开

'; document.body.appendChild(div);}// 设置stylefunction loadStyleText(cssText) { var style = document.createElement('style'); style.rel = 'stylesheet'; style.type = 'text/css'; try { style.appendChild(document.createTextNode(cssText)); } catch (e) { style.styleSheet.cssText = cssText; //ie9以下 } var head = document.getElementsByTagName("head")[0]; //head标签之间加上style样式 head.appendChild(style);}//CSS样式var cssText = "#weixin-tip{position: fixed; left:0; top:0; background: rgba(0,0,0,0.8); filter:alpha(opacity=80); width: 100%; height:100%; z-index: 100;} #weixin-tip p{text-align: center; margin-top: 10%; padding:0 5%;}";if (is_weixin()) { loadHtml(); loadStyleText(cssText);}
IMG_1185.PNG 大概是内容大概如下:

 

红标题的后面还有一段白色说明文字,因为背景是白色所有看不到

 

转载于:https://www.cnblogs.com/yuzuoxiang/p/5126926.html

你可能感兴趣的文章
KTAG K-TAG ECU Programming Tool
查看>>
javascript模板方法模式
查看>>
大数据网络诊断系统项目总结
查看>>
poj 2697 A Board Game(bfs+hash)
查看>>
virtualbox centos安装增强工具
查看>>
利用Spring创建定时任务
查看>>
jQuery按键事件响应的Demo
查看>>
Android 数据库加密
查看>>
java 属性封装
查看>>
eclipse 10个常用 快捷键
查看>>
SFTP文件上传与下载
查看>>
Leetcode:minimum_depth_of_binary_tree解决问题的方法
查看>>
VS2013验证控件出现 WebForms UnobtrusiveValidationMode 必须“jquery”ScriptResour......错误的解决方案...
查看>>
cucumber java从入门到精通(4)Scenario Outline及数据驱动
查看>>
于CentOS 6.5编译器安装Git 1.8
查看>>
undefined function openssl_x509_read
查看>>
LeetCode:Balanced Binary Tree
查看>>
poj 1664 把平果
查看>>
报文时箱子,实体是货物
查看>>
angularJS ngClass如何使用
查看>>