This is just a really, really simple tutorial that could be found by searching on Google or any other website that focuses on programming. But in this tutorial I am going to be showing you how to show different content to people on mobile/handheld devices such as iPads, iPhones, BlackBerrys etc.
It's really simple and can be done on about 5 lines.
All you have to do is put the following code in your <head></head> tags.
Simple, right? But how do I show content to specific handheld devices, and not all of them? Easy, just another if statement:
You can keep adding conditions to the code above if you like.
Anyway, I hope this works because yet again, I coded this in the post box on DevBest and I'm not the best at explaining things.
So good luck with whatever you use it for.
- Mark.
It's really simple and can be done on about 5 lines.
All you have to do is put the following code in your <head></head> tags.
PHP:
<script type="text/javascript" language="javascript">
var mobileUser = navigator.userAgent.match(/(iPod)|(iPhone)|(iPad)|(webOS)|(BlackBerry)|(android)/i); /* will return (bool) true if the user is on a device that contains one of the strings in the brackets, (bool) false if not. */
if ( mobileUser ) /* is mobileUser set to 'true'? */
{
alert( "This website is built for desktop computers and laptops, some functions may not work properly on this site!"); /* an alert to show to the user */
} /*end the if statement*/
</script>
Simple, right? But how do I show content to specific handheld devices, and not all of them? Easy, just another if statement:
PHP:
<script type="text/javascript" language="javascript">
var uA = navigator.userAgent; /* assign the value of the users 'userAgent' to a string called 'uA' to shorten our code */
if ( uA.indexOf( "iPod" ) > 0 ) /* the user is on an iPod touch */
{
alert( "Welcome, iPod touch user!" );
}
elseif ( uA.indexOf( "iPad" ) > 0 )
{
alert( "You are currently viewing this website on an iPad!" );
} /*end if statement*/
</script>
Anyway, I hope this works because yet again, I coded this in the post box on DevBest and I'm not the best at explaining things.
So good luck with whatever you use it for.
- Mark.