www.webdeveloper.com
Results 1 to 7 of 7

Thread: Toggle Between Mobile and Standard Websites?

  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Toggle Between Mobile and Standard Websites?

    I created a very simple mobile version for my website. I switch to it by detecting the visitor's viewing width of their screen. If it's less than 400 pixels wide, it switches the visitor to the mobile version.

    Here's the question...

    I want to give the visitor the option of swtiching back to the normal website. However, I can't just put a link to the normal website because it would detect their viewing width and send them right back to the mobile version.

    What's the best method to allow them to switch back and forth between the mobile version of the website and the normal version of the website?

    Based on what I've read, I should install a cookie that toggles each time the visitor changes their preference between the mobile version and the normal version of the website.

    The problem is I have no experience creating a cookie and it's a little more complex than I anticipated. With that said, here's specifically what I want to do...

    Using Javascript, I want to write a cookie that has a variable called mobileSwitch.

    By default, I want the value of mobileSwitch to be 'off'.

    I want to include a button on the page that will turn the value of mobileSwitch to 'on' and then take the visitor to the mobile version of my website.

    Thanks in advance for any advice code examples.

    Bill

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    You can not avoid using cookies. You may also use the HTML5 new features, but, unfortunately, browsers like IE7 and IE8 will not render HTML5.

    So, back to the cookies:

    http://www.quirksmode.org/js/cookies.html

  3. #3
    Join Date
    Feb 2012
    Posts
    2
    Quote Originally Posted by Kor View Post
    You can not avoid using cookies. You may also use the HTML5 new features, but, unfortunately, browsers like IE7 and IE8 will not render HTML5.

    So, back to the cookies:

    http://www.quirksmode.org/js/cookies.html
    I did end up using cookies and writing a little Javascript code to handle the cookie. But during my research, I did find another option. I didn't do a lot of research into it, but I think "sessions" in PHP can do the trick without cookies.

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by MysticKnight View Post
    I did end up using cookies and writing a little Javascript code to handle the cookie. But during my research, I did find another option. I didn't do a lot of research into it, but I think "sessions" in PHP can do the trick without cookies.
    I would not be so sure. A session variable is active only as long as the user remains within the same domain. If the user closes his browser or he quits the domain, the session is gone, so that no information are stored. Except, maybe, if you use a login user/password and a database, but this is another discussion.

    But you may use PHP cookies, if you feel more comfortable than with JavaScript cookies.

    See also:
    http://php.about.com/od/learnphp/qt/session_cookie.htm
    http://www.tuxradar.com/practicalphp/10/0/0

  5. #5
    Join Date
    May 2012
    Posts
    2
    The mobile/full view is controlled by a cookie, and there is some chance something interfered with that.

  6. #6
    Join Date
    Sep 2006
    Location
    new york
    Posts
    266

    Not Kosher

    It may not be legitimate (certainly not "professional"), but an easy option would be to have link back to alternate full-scale page that does NOT have a Javascript detecting viewer's screen size

  7. #7
    Join Date
    Mar 2012
    Posts
    1,528
    You can avoid using cookies by using GET variables to control to auto-sensing. E.g In PHP:

    Mobile website:
    ---------------------

    <body>
    <a href="index.php?auto=N" >click for normal version</a>

    </body>

    Normal Website:
    ----------------------

    <body>
    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    if ( $_GET['auto'] == NULL ) { $auto='Y'; }
    else { $auto=$_GET['auto'];
    }
    if ($auto=='Y') {
    /* auto sensing code goes here */;
    } ?>
    <!-- continue here -->

    </body>

    Note: This is just an example of using GET variables. It's written in PHP bcause I'm more familiar with that than JavaScript. If the auto-sensing is in JS, it would make sense to do this in JS.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles