Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
195
rated 0 times [  196] [ 1]  / answers: 1 / hits: 5548  / 10 Years ago, fri, may 2, 2014, 12:00:00

I have this simple utility code to check for browser User-Agent:



public class UserAgentHelper {
public static boolean isMobile(){
String userAgent = getUserAgent();
return userAgent.contains(ipad);
}
public static boolean isAndroid(){
return getUserAgent().contains(android);
}
public static native String getUserAgent() /*-{
return navigator.userAgent.toLowerCase();
}-*/;
}


I need to check if the browser is mobile or desktop. That is the main point. I'm starting with checking if the browser is iPad browser however this code fails sometimes when the string ipad is not there, when I tested on such browser sometimes the keyword is applewebkit, but who knows there could be more. So is there a




  • GWT library for this?

  • or a Javascript library for this?


More From » java

 Answers
21

Try



    //Detect iPhone
navigator.platform.indexOf(iPhone) != -1

//Detect iPod
navigator.platform.indexOf(iPod) != -1


For more info have a look at Detect iPad


[#45605] Thursday, May 1, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
siena

Total Points: 199
Total Questions: 91
Total Answers: 91

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;