JS检测是否有企业微信应用程序
一、问题
- 有一个小需求:让点击一个按钮弹出桌面的企业微信应用程序,如果没有,就跳转到下载页面。
二、解决
- 需要下载一个插件:protocolcheck.js 或者直接复制文章后面的代码。
- 将该文件引入
index.html
中
<script src="./protocolCheck.js"></script>
- 点击事件定义为:
const ___ = () => {window.protocolCheck("wxwork://", function () {// 没有安装时的执行函数const clickUp = window.confirm("没有该应用,是否去下载");if (clickUp) {window.open("https://work.weixin.qq.com/#indexDownload");}});
};
- 大功告成
三、protocolcheck.js
(function (f) {if (typeof exports === "object" && typeof module !== "undefined") {module.exports = f();} else if (typeof define === "function" && window.define.amd) {window.define([], f);} else {var g;if (typeof window !== "undefined") {g = window;} else if (typeof global !== "undefined") {g = global;} else if (typeof window.self !== "undefined") {g = window.self;} else {g = this;}g.protocolCheck = f();}
})(function () {return (function e(t, n, r) {function s(o, u) {if (!n[o]) {if (!t[o]) {var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);var f = new Error("Cannot find module '" + o + "'");throw ((f.code = "MODULE_NOT_FOUND"), f);}var l = (n[o] = { exports: {} });t[o][0].call(l.exports,function (e) {var n = t[o][1][e];return s(n ? n : e);},l,l.exports,e,t,n,r);}return n[o].exports;}var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) s(r[o]);return s;})({1: [function (require, module, exports) {function _registerEvent(target, eventType, cb) {if (target.addEventListener) {target.addEventListener(eventType, cb);return {remove: function () {target.removeEventListener(eventType, cb);},};} else {target.attachEvent(eventType, cb);return {remove: function () {target.detachEvent(eventType, cb);},};}}function _createHiddenIframe(target, uri) {var iframe = document.createElement("iframe");iframe.src = uri;iframe.id = "hiddenIframe";iframe.style.display = "none";target.appendChild(iframe);return iframe;}function openUriWithHiddenFrame(uri, failCb, successCb) {var timeout = setTimeout(function () {failCb();handler.remove();}, 1000);var iframe = document.querySelector("#hiddenIframe");if (!iframe) {iframe = _createHiddenIframe(document.body, "about:blank");}var handler = _registerEvent(window, "blur", onBlur);function onBlur() {clearTimeout(timeout);handler.remove();successCb();}iframe.contentWindow.location.href = uri;}function openUriWithTimeoutHack(uri, failCb, successCb) {var timeout = setTimeout(function () {failCb();handler.remove();}, 1000);//handle page running in an iframe (blur must be registered with top level window)var target = window;while (target !== target.parent) {target = target.parent;}var handler = _registerEvent(target, "blur", onBlur);function onBlur() {clearTimeout(timeout);handler.remove();successCb();}window.location = uri;}function openUriUsingFirefox(uri, failCb, successCb) {var iframe = document.querySelector("#hiddenIframe");if (!iframe) {iframe = _createHiddenIframe(document.body, "about:blank");}try {iframe.contentWindow.location.href = uri;successCb();} catch (e) {if (e.name === "NS_ERROR_UNKNOWN_PROTOCOL") {failCb();}}}function openUriUsingIEInOlderWindows(uri, failCb, successCb) {if (getInternetExplorerVersion() === 10) {openUriUsingIE10InWindows7(uri, failCb, successCb);} else if (getInternetExplorerVersion() === 9 ||getInternetExplorerVersion() === 11) {openUriWithHiddenFrame(uri, failCb, successCb);} else {openUriInNewWindowHack(uri, failCb, successCb);}}function openUriUsingIE10InWindows7(uri, failCb, successCb) {var timeout = setTimeout(failCb, 1000);window.addEventListener("blur", function () {clearTimeout(timeout);successCb();});var iframe = document.querySelector("#hiddenIframe");if (!iframe) {iframe = _createHiddenIframe(document.body, "about:blank");}try {iframe.contentWindow.location.href = uri;} catch (e) {failCb();clearTimeout(timeout);}}function openUriInNewWindowHack(uri, failCb, successCb) {var myWindow = window.open("", "", "width=0,height=0");myWindow.document.write("<iframe src='" + uri + "'></iframe>");setTimeout(function () {try {myWindow.location.href = null;myWindow.setTimeout("window.close()", 1000);successCb();} catch (e) {myWindow.close();failCb();}}, 1000);}function openUriWithMsLaunchUri(uri, failCb, successCb) {navigator.msLaunchUri(uri, successCb, failCb);}function checkBrowser() {var isOpera =!!window.opera || navigator.userAgent.indexOf(" OPR/") >= 0;var ua = navigator.userAgent.toLowerCase();return {isOpera: isOpera,isFirefox: typeof InstallTrigger !== "undefined",isSafari:(~ua.indexOf("safari") && !~ua.indexOf("chrome")) ||Object.prototype.toString.call(window.HTMLElement).indexOf("Constructor") > 0,isIOS:/iPad|iPhone|iPod/.test(navigator.userAgent) &&!window.MSStream,isChrome: !!window.chrome && !isOpera,isIE: /*@cc_on!@*/ false || !!document.documentMode, // At least IE6};}function getInternetExplorerVersion() {var rv = -1;if (navigator.appName === "Microsoft Internet Explorer") {const ua = navigator.userAgent;const re = new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");if (re.exec(ua) != null) rv = parseFloat(RegExp.$1);} else if (navigator.appName === "Netscape") {const ua = navigator.userAgent;const re = new RegExp("Trident/.*rv:([0-9]{1,}[.0-9]{0,})");if (re.exec(ua) != null) {rv = parseFloat(RegExp.$1);}}return rv;}module.exports = function (uri, failCb, successCb, unsupportedCb) {function failCallback() {failCb && failCb();}function successCallback() {successCb && successCb();}if (navigator.msLaunchUri) {//for IE and Edge in Win 8 and Win 10openUriWithMsLaunchUri(uri, failCb, successCb);} else {var browser = checkBrowser();if (browser.isFirefox) {openUriUsingFirefox(uri, failCallback, successCallback);} else if (browser.isChrome || browser.isIOS) {openUriWithTimeoutHack(uri, failCallback, successCallback);} else if (browser.isIE) {openUriUsingIEInOlderWindows(uri,failCallback,successCallback);} else if (browser.isSafari) {openUriWithHiddenFrame(uri, failCallback, successCallback);} else {unsupportedCb();//not supported, implement please}}};},{},],},{},[1])(1);
});
JS检测是否有企业微信应用程序相关推荐
- 企业微信小程序_授权登录接口获取用户userid
文章目录 一.前置知识 1. 阅读 企业微信小程序开发文档 2. 企业微信小程序登录流程 3. 微信小程序区别 二.前端部分 2.1. 调用登录接口 2.2. 请求后端接口 2.3. 项目源码 三.后 ...
- 企业微信小程序_获取准确定位的方法及解决定位不准确的问题
文章目录 一.经验分享 1. 微信api现状 2. 解决方案 3. 适用场景 二.小程序集成腾讯定位服务 2.1. 注册腾讯开发者 2.2. 创建应用 2.3. 添加key 2.4. 下载sdk 2. ...
- 企业微信小程序获取手机号?
一.确定小程序是开发企业内部应用,还是开发第三方应用. 如果是开发企业内部应用,也就是应用自建的可以使用 wx.qy.getMobile 这个api 去获取手机号wx.qy.getMobile 调用 ...
- 企业微信小程序_小程序开发工具及真机调试_host配置及代理
文章目录 一.开发前准备 1. 开发文档 2. 工具安装 3. 安装插件 4. 调整编译模式 5. 选择企业 6. PC 调试前端 7. PC 调试后端 二.甄姬调试前端 2.1. 预览小程序 2.2 ...
- 微信开发者平台切换企微账号与企业微信小程序模式
1点击下面图片红框这 2 然后在点击弹窗里的选择企业 企业微信小程序模式也得在工具里插件里头安装如下图插件
- 微信开发者工具如何打开企业微信小程序
在微信开发者工具中进行打开显示: 但真机调试扫码打开,就马上闪退,而且不可能一直在手机调试 解决办法: 1-微信开发者工具打开 工具–插件 2-模拟器插件安装企业微信小程序模拟器 3-切换编译模式
- 企业微信小程序wx.qy.login 的调用调试踩坑
企业微信小程序wx.qy.login 的调用调试踩坑 起步 在企业微信的开发过程中有很多坑,一切以企业微信开发文档为准. 近期我公司项目需要我联调开发企业微信小程序,以前没开发过,所以一切只能跟着企业 ...
- wxwork和wx.qy判断企业微信小程序编译运行环境
文章目录 前言 1.企业微信 2.个人微信 3.应用 前言 根据官方文档有两种方式可以判断: 1.方法一: 调用获取系统信息API[uni.getSystemInfoSync()],获取environ ...
- 企业微信小程序开发(行事历)
企业微信小程序开发(行事历) 背景:最近公司外出办公的同事很多,公司需要一个小程序来记录员工的出行记录,借此来统计出行成效 主要平台 PC端,安卓端 设计思想 1.普通员工,在小程序端可以发起一次出行 ...
最新文章
- CodeGen CreateFile实用程序
- 处理表格数据时,去除表头两种写法,jquery 删除表头之外的数据
- Linux下配置DNS
- 《四世同堂》金句摘抄(十二)
- 算命数据_未来的数据科学家或算命精神向导
- 获取自动增涨列的表中添加完成后的数据
- lampp mysql 等待响应时间很长_Apache 打开网页的时候等待时间过长的解决方案
- 简单 fibonacci 函数
- 软件需求说明书/ 概要设计说明书/项目开发计划/详细设计说明书模版(说明要点及要点解释)
- 马哥linux2018目录,2018-01-02 马哥Linux学习笔记—Linux系统基础使用入门
- 阿里巴巴的安全能力究竟是什么水平?
- google 阅读器
- InkScape:制作简易LOGO
- 剑指offer算法题分析与整理(二)
- 由浅入深MFC学习摘记--第三部分
- Vue刷新页面重新加载
- python入门笔记之初步了解代码
- Android逆向之破解某僵尸游戏
- 开源基金回测网站:让数据告诉你定投财富密码
- [译] 如何从一个业余爱好者成长成为专业开发者
热门文章
- Chromebook2013 由Fyde os 升级为Deepin v20.2.1 (一)
- CSS属性 – text-decoration(常用)
- 最详细的教程axure新手入门:Axure教程
- 人人都能当“苍天哥” 手把手教你制作游戏视频
- CSSHTMLREM制作手机端网页(小练习)
- 边缘计算系统逻辑架构:云、边、端协同,定义及关系
- c++操作符重载,拷贝构造函数和友…
- 提供免费可商用的优秀背景视频素材——COVERR
- 如何推进中小学STEM教育课程开发和实施
- 采用html 的a标签,href连接为文件时无法下载解决方案