0

Right now, if you go to my web site on a mobile device, you'll be redirected to a subdomain thanks to the following code. Which checks to see if your screens width is below 800 or if you're on an iphone, ipad, or ipod.

One thing I'd like to be able to do is allow the visitor to view the full site if they want to. How do I allow them to bypass this should they choose to do so?

<script type="text/javascript">
<!--
    if (screen.width <= 800) {
        document.location = "http://m.site.ca";
    }
    //-->
</script>
<script type="text/javascript">
    // <![CDATA[
    if ((navigator.userAgent.indexOf('iPhone') != -1) ||  
       (navigator.userAgent.indexOf('iPod') != -1) ||     
       (navigator.userAgent.indexOf('iPad') != -1)) {                   
           document.location = "http://m.site.ca";
    } // ]]>
</script>
Frantumn
  • 1,545
  • 6
  • 32
  • 57
  • you could use a [confirm dialog box](https://developer.mozilla.org/en-US/docs/Web/API/Window.confirm) - in conjuction with the cookie idea so the user wouldn't have to confirm which site they wanted to view each time they visited a new page. You may also want to check for mobile device by [using this](http://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-handheld-device-in-jquery) rather than checking the screen width – Pete Oct 10 '13 at 13:13

1 Answers1

0

Cookies are probably the easiest way.

Just set a cookie if they ask to go to the "desktop" version of the site on mobile, and add a check for that cookie before your redirect script that prevents its execution if they've decided to browse the desktop version from mobile.

The wonderful jQuery Cookie plugin is very lightweight and makes working with cookies a breeze.

Ennui
  • 9,633
  • 3
  • 32
  • 42