Disable code if a handheld device?

Permalink
Is there a way to disable a few lines of code if the user is viewing the website on a handheld device?

I have a BG image that I need to switch off but it is loaded using JS so I want to disable the JS altogether

Thanks in advance

----

Edit: I have just found this...
http://detectmobilebrowsers.mobi/...

reading through it now

dancer
View Replies:
12345j replied on at Permalink Reply
12345j
<?php 
      if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'Android') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'Blackberry') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'OperaMobi') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'IEMobile') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'Jasmine') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'Fennec') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'Blazer') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'Minimo') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'MOT-') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'Nokia') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'SAMSUNG') ||
    strstr($_SERVER['HTTP_USER_AGENT'], 'Polaris') ||

will detect mobile browsers and give them the name mobile. then call $device == "mobile" for further use (or you could wrap this in an if else statement
dancer replied on at Permalink Reply
dancer
Hey 12345j

Thanks for this. I suppose for me I would need:

<?php if ($device != "mobile"); ?>
my line of javascript
<?php endif; ?>


So normal computers will use the code and mobile devices won't

Many thanks again
12345j replied on at Permalink Reply
12345j
sorrey for not replying sooner, i didn't get the email. I believe negatives for php go at the beginning of the rule- so it would be something like
if (!$device == "mobile")
but im not great at php. I might link it in with an if else though, so
if ($device == "mobile"){
   // link to mobile.css if you want a bg color
} 
else {
    // javascript here
}

but that could be just me. I guess its just my coding style, but thats what I like to do.