Skip to content

URL Scheme 调用 App

Published: at 11:12 AMSuggest Changes

url Scheme 调用 App

// 调用 App
function callApp(schema, timeOut) {
  let timer,
    start = new Date().getTime();
  let myPromise = new Promise((resolve, reject) => {
    window.location.href = schema;
    window.addEventListener("visibilitychange", () => {
      if (document.visibilityState === "hidden") {
        clearTimeout(timer);
        resolve();
      }
    });
    timer = setTimeout(() => {
      let end = new Date().getTime();
      if (end - start > timeOut + 1000) {
        clearTimeout(timer);
        resolve();
      } else {
        reject();
      }
    }, timeOut);
  });
  return myPromise;
}

Previous Post
幻灯片左右两侧显示一小块预览
Next Post
Node.js 错误代码 ERR_OSSL_EVP_UNSUPPORTED