Java Servlets – How do I detect if a user is from a mobile device?
I’m using the TinyMCE javascript editor, and it doesn’t work on the iphone. How can I detect if the user is coming from a mobile device?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since you’d like to change the client side behaviour depending on the client, best is to handle this at the client side rather than the server side.
In CSS world, you can hook on the media type to apply styles depending on the media used. Most used media types are screen (usually PCs), handheld (usually mobiles) and print (for the printed page).
You can make use of it to hide the editor by just the following rule in your CSS:
You can even specify separate stylesheets depending on the media used.
If the problem is actually more that it doesn’t work because JavaScript is disabled on the particular client, then you better have to execute the particular CSS when JS is disabled:
Or the other way round, initially hide it and then show it when JS is enabled:
This is more reliable than sniffing the agent in the server side.