Jump to content

Tip: detect Windows Tablet and Windows Phone


K1kk0z90
 Share

Recommended Posts

Hi all! :)

I want to share with you what I learned yesterday after searching a lot on the internet: how to detect whether a game is running on a Windows Tablet or on Windows Phone.

The problem is that checking that the user's OS is Windows, is not enough to afferm they're running the game on a desktop PC. There are also Windows tablets, and a tablet user wants a mobile optimized experience.

 

The trick is to check the user agent string. We assume that a user on a Windows Tablet or Phone is using Internet Explorer. This is an example of user agent string sent by IE10 if running on a tablet:

 

Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; Touch)

 

As you can see, the user agent string contains the string "Touch". This appears only on Windows tablets, and not desktops. So if we want to check whether our game is running on a Windows tablet we can write this function to check it:

function is_win_tablet(){	return (navigator.userAgent.toLowerCase().indexOf("windows nt") != -1 &&		navigator.userAgent.toLowerCase().indexOf("touch") != -1);}

Detect Windows Phone is easier: we only have to look for the OS name in the user agent string:

function is_winphone(){	return (navigator.userAgent.toLowerCase().indexOf("windows phone") != -1);}

If you use GameMaker like me, using these functions will solve the problem that GM, on HTML5, consider the same thing Windows, Windows RT and Windows Phone. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...