H5 page wakes up app and judges app installation

Before reading this article, you should first have a basic understanding of js and a certain understanding of Scheme and intent. More code


Using other people's libraries, you can omit some code, call app-lib can wake up app directly, and wake up failed callback, but you have to pass in Scheme.

The callapp-lib library may have a problem, and I don't understand it thoroughly. It doesn't give you the ability to wake up successful callback s, so we need to make it up for ourselves.
File: callapp-lib

import CallApp from 'callapp-lib'
const option = {
    scheme: {
        protocol: 'itms-beta',
    outChain: {
        protocol: 'itms-beta',
        path: '',
    appstore: 'http://www.apple.com',
    yingyongbao: 'http://www.zhihu.com',
    fallback: 'https://www.baidu.com',
    timeout: 3000,
const lib = new CallApp(option);
const callButton = document.querySelector('#call-button');
callButton.addEventListener('click', () => {
    vm.is_show = 1
        mask: true,
        message: 'Loading...'
        path: '/text',
        callback: function () {
            vm.is_show = 0
            self.$toast.fail('open TestFlight fail,Please download the support software first. TestFlight');
            return false

Check whether the page is cut to run in the background and listen for the event

is_show is to prevent duplicate loading

 var hidden, state, visibilityChange;
if (typeof document.hidden !== "undefined") {
    hidden = "hidden";
    visibilityChange = "visibilitychange";
    state = "visibilityState";
} else if (typeof document.mozHidden !== "undefined") {
    hidden = "mozHidden";
    visibilityChange = "mozvisibilitychange";
    state = "mozVisibilityState";
} else if (typeof document.msHidden !== "undefined") {
    hidden = "msHidden";
    visibilityChange = "msvisibilitychange";
    state = "msVisibilityState";
} else if (typeof document.webkitHidden !== "undefined") {
    hidden = "webkitHidden";
    visibilityChange = "webkitvisibilitychange";
    state = "webkitVisibilityState";
document.addEventListener(visibilityChange, function () {
  // eslint-disable-next-line
  //Judging from this, don't repeat Downloads
    if (vm.is_show == 1) {
      vm.is_show = 0

}, false);

It's not easy to be original. Please attach the original source link for reprint. Thank you.
Link https://lihengc.github.io/2019/09/24/H5%E7%BD%91%E9%A1%B5%E5%94%A4%E9%86%92 app-%E5%88%A4%E6%96%ADapp%E5%AE%89%E8%A3%85/

Tags: github

Posted on Tue, 08 Oct 2019 09:16:00 -0700 by Stathy