Quantcast
Channel: windows store apps – Timmy Kokke
Viewing all articles
Browse latest Browse all 18

Detecting Phone, Desktop or Web with WinJS

0
0

I’m my previous post I showed how you can add a website to a universal project and share some JavaScript between all three. This is nice, but I will run into a situation where you’ll have some code that is not supposed to run on one of the platforms. In the C# world you can use compiler directives in situations like this. In JavaScript this is not possible (Although you could create constructions that mimic directives using Grunt for example). WinJS has some functionality build in that can help finding out what platform you are using.

There are two properties on the utilities in WinJS you’ll need:

Here’s a small example of you could use it:

if (WinJS.Utilities.isPhone) {
    console.log("Phone");
} else {
    if (WinJS.Utilities.hasWinRT) {
        console.log("WinApp");
    } else {
        console.log("Else");
    }
}

Viewing all articles
Browse latest Browse all 18

Latest Images

Trending Articles





Latest Images