如何从 Javascript 检测 Win8/Metro

发布于 2024-12-20 15:15:49 字数 163 浏览 7 评论 0原文

如何从 Javascript 检测环境是 Windows 8 Metro 应用程序?

更新:澄清一下,我的 Javascript 代码既可以在任何浏览器上运行,也可以作为 Win8 应用程序的一部分运行。由于Win8应用程序对JS代码施加了安全限制,因此我想检测代码何时在Win8应用程序中运行。

How does one detect that the environment is Windows 8 Metro application from Javascript?

UPDATE: To clarify, my Javascript code runs both on any browser and as part of an Win8 application. Since Win8 applications impose security restrictions for JS code, I want to detect when the code is running in Win8 app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

九歌凝 2024-12-27 15:15:49

回答我自己:

检测此问题的一种方法是检查某些 MS 特定对象或名称空间是否存在。其中之一是Windows。例如:

if (typeof Windows != "undefined") {
  // Running in Win8 app
} else {
  // Running in a browser
}

Answering myself:

One way to detect this is to check the existence of some MS-specific objects or namespaces. One of them is Windows. For example:

if (typeof Windows != "undefined") {
  // Running in Win8 app
} else {
  // Running in a browser
}
‖放下 2024-12-27 15:15:49

我认为你可以使用:

WorkerNavigator.useragent

属性来检测它

i think you could use:

WorkerNavigator.useragent

property to detect it

醉生梦死 2024-12-27 15:15:49

我使用这段代码:

var isWinJS = !!window.Windows && /^ms-appx:/.test(location.href);

I use this code:

var isWinJS = !!window.Windows && /^ms-appx:/.test(location.href);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文