Kyberias
Kyberias

Reputation: 1251

How to detect Win8/Metro from Javascript

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.

Upvotes: 2

Views: 2771

Answers (3)

amartynov
amartynov

Reputation: 4175

I use this code:

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

Upvotes: 0

Kyberias
Kyberias

Reputation: 1251

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
}

Upvotes: 2

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

i think you could use:

WorkerNavigator.useragent

property to detect it

Upvotes: 0

Related Questions