本文介绍了用于检查PWA或Mobile Web的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇是否有人知道基于javascript的方法来检测网络体验是作为PWA(渐进式网络应用程序)运行还是只是作为标准移动网站运行(具有完整的浏览器UI)。

I was curious if anyone knew a javascript based method for detecting whether the web experience was being run as a PWA (progressive web app) or it was simply being run as a standard mobile website (with full browser UI).

已安装的PWA与尚未注册服务工作者和/或应用程序缓存的PWA之间是否存在任何差异?

Is there any difference between a PWA that is "installed" versus one that isn't but still has the service worker and/or app cache registered?

推荐答案

如果这是出于分析目的,您可以在清单文件中设置起始URL以包含查询字符串参数,例如:

If this is for analytical purposes you could set the start URL in the manifest file to include a query string parameter, ex:

"start_url": "./?mode=standalone"

然后在您的JavaScript中,您可以检查此查询字符串参数。

Then in your JavaScript you are able to check for this query string parameter.

或者您可以使用以下方式登录JavaScript:

Alternatively you could check in JavaScript using:

if (window.matchMedia('(display-mode: standalone)').matches) {
  console.log("This is running as standalone.");
}

这篇关于用于检查PWA或Mobile Web的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 09:05