admin管理员组

文章数量:1327665

I need a solution which will allow me to detect if the browser is mobile (i.e. iPhone, Android phone), desktop, or tablet (i.e. iPad, Nook). Based on the detection, it'll redirect to the appropriate site.

I could use WURFL but this is for a private pany, and they are cheap and will not pay for the mercial license. I don't mind making the WURFL code itself public; but the class will be manipulated in a JSP page. If I only am required to make the class that uses the WURFL API code public, and not the surrounding JSP code, perhaps I can use it. That's the question: Behind a mercial entity, what is considered public information, with respect to the WURFL API? Do I have to make my JSP page open-source, too?

If I can't use WURFL, without paying for a mercial license, is there another bundled solution for Java or even JavaScript?

Thank you very much.

I need a solution which will allow me to detect if the browser is mobile (i.e. iPhone, Android phone), desktop, or tablet (i.e. iPad, Nook). Based on the detection, it'll redirect to the appropriate site.

I could use WURFL but this is for a private pany, and they are cheap and will not pay for the mercial license. I don't mind making the WURFL code itself public; but the class will be manipulated in a JSP page. If I only am required to make the class that uses the WURFL API code public, and not the surrounding JSP code, perhaps I can use it. That's the question: Behind a mercial entity, what is considered public information, with respect to the WURFL API? Do I have to make my JSP page open-source, too?

If I can't use WURFL, without paying for a mercial license, is there another bundled solution for Java or even JavaScript?

Thank you very much.

Share Improve this question edited Apr 26, 2012 at 16:47 user717236 asked Apr 26, 2012 at 16:34 user717236user717236 5,03920 gold badges67 silver badges102 bronze badges 4
  • 1 detectmobilebrowsers. however, I don't know how to do this in Java. – user1150525 Commented Apr 26, 2012 at 16:39
  • 1 stackoverflow./questions/142273/… – user1150525 Commented Apr 26, 2012 at 16:41
  • @Bennika: That's okay, I'll attempt a Java solution and report my findings here. – user717236 Commented Apr 26, 2012 at 16:48
  • You could use wurfl.js to achieve this (web.wurfl.io) – Elliot Fehr Commented May 7, 2015 at 18:41
Add a ment  | 

4 Answers 4

Reset to default 2

You should look upon sebarmeli/JS-Redirection-Mobile-Site, it is based on javascript, both free and open source with ease of use and robustness.

If you like WURFL and JavaScript is an option, I receommend you check out http://wurfl.io/

In a nutshell, if you import a tiny JS file:

<script type='text/javascript' src="//wurfl.io/wurfl.js"></script>

you will be left with a JSON object that looks like:

{
 "plete_device_name":"Google Nexus 7",
 "is_mobile":true,
 "form_factor":"Tablet"
}

(that's assuming you are using a Nexus 7, of course) and you will be able to do things like:

if(WURFL.form_factor == "Tablet"){
    //dostuff();
}

This is what you are looking for.

Disclaimer: I am the WURFL inventor and I work for the pany that offers this free service. Thanks.

Be aware that regex-based solutions (such as JS-Redirection-Mobile-Site) will fail to correctly categorise some browsers. The biggest problem right now is Android tablets, many of which will be recognised as a mobile device by these solutions. If you really want to be sure about getting everything right you're going to have to use a server side solution, but it's possible that Android tablets don't yet constitute enough traffic to the site in question to be worth dealing with.

Disclaimer: I work for a provider of server side device detection solutions.

Have a look at 51degrees.mobi who provide some of the data you need under the Mozilla Public Licence version 2.

There is also a self contained PHP version at SourceForge which is quick to implement.

本文标签: