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

风格不统一 提交于 2021-01-29 07:12:05

问题


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


回答1:


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




回答2:


window.navigator.pointerEnabled

This method returned true Surface devices.....




回答3:


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



来源:https://stackoverflow.com/questions/29091862/how-to-check-if-device-is-windows-surface-tablet-and-browser-is-chrome-or-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!