3

sorry if this is a bit on the easy side, but I haven't found an answer online (yet)...

I'd like to have one link that points to two different URLs, depending on the device accessing the site. So, for example I click a link and if I'm on anything using a touchscreen, it sends me to page01.htm but if I'm accessing the site with a mouse (ie something that can hover), it sends me to page02.htm.

Essentially, this is to fake a rollover effect on touchscreens. On the pc version, the rollover effect highlights different states on a map, which then click through to the state-specific page. On touchscreen, we want to be able to click the state on the map (which would highlight the state), and then to click again for it to go through to the state-specific page.

If there's a better way to do this, I'm totally open to suggestions! :-)

Thanks!

Eve
  • 31
  • 1

1 Answers1

0

You can try something like this.

<?php
function istouch() {
    //detect if client device is touch (not 100% reliabe I guess)
    if(preg_match('~iPad|iPhone|iPod|Android|webOS~',$_SERVER['HTTP_USER_AGENT'])) return true;
    else return false;
}
?>

Then when user access your page, and this function returns true you can do redirection to page you need.

Vuk Stanković
  • 7,864
  • 10
  • 41
  • 65
  • Yes, I think that's along the lines of what I need! But where would I add this code? (I'm using wordpress.) And where do I put the redirection? (Sorry, I'm a bear of very little brain tonight! I really appreciate your help!) – Eve Dec 13 '12 at 09:44
  • You can add it to theme `functions.php` file and use `wp_safe_redirect` – Vuk Stanković Dec 13 '12 at 10:38