How to detect mobile browser using jQuery or in some other SIMPLE way..? [duplicate]

淺唱寂寞╮ 提交于 2019-11-27 15:32:47

问题


Possible Duplicate:
best way to detect handheld device in jQuery

I want to make a mobile version of my web app. How I can run a function that will detect if a request is being made from a desktop or mobile browser?

This is so that if the user is requesting from a mobile browser and they click on a link, rather than go to the actual page, it should get hijacked and do some other event..

Thanks in advance..


回答1:


There are a few scripts on Detect Mobile Browser that redirect mobile visitors on the server side or with JavaScript or jQuery.




回答2:


You could use the following to get the platform

navigator.platform

And this to get the browser app

navigator.appName

Example:

// Detects if it is an Android device
var android = (navigator.platform.indexOf("android")>=0);
if (android) {
   // Do something
}

Also, there is the Advanced Browser Check jQuery Plugin, though it seems like it might be overkill.



来源:https://stackoverflow.com/questions/5045615/how-to-detect-mobile-browser-using-jquery-or-in-some-other-simple-way

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