pareshm
pareshm

Reputation: 4984

How to check if device is Windows Surface Tablet and browser is chrome or IE

How to check if device is Windows Surface Tablet and browser is chrome or IE using Javascript. i have tried following code

function is_touch_device() 
{  
  try {  
    document.createEvent("TouchEvent");  
    return true;  
  } catch (e) {  
    return false;  
  }  
}
if(is_touch_device() )
{
    if(navigator.userAgent.toLowerCase().indexOf('chrome')>-1)
     {
       //some stuff
      }
}

i have searched for useragent but i an not getting exact for surface. how to check if device is surface and browser is chrome or IE

Upvotes: 0

Views: 3381

Answers (3)

Sanya Kravchuk
Sanya Kravchuk

Reputation: 31

window.navigator.pointerEnabled

This method returned true Surface devices.....

Upvotes: 2

Shouvik
Shouvik

Reputation: 447

Though you can use navigator object to serve your purpose, I would suggest you to use modernizer for the same.

Upvotes: 1

floor
floor

Reputation: 1572

Using the navigator object you can access these data fields

navigator.appName  <- gets app name may be misleading so also get the appCodeName
navigator.appCodeName; <-- alternate name
navigator.platform; <-- platform the user is on

http://www.w3schools.com/js/js_window_navigator.asp

Upvotes: 2

Related Questions