Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ...if viewed on a mobile phone

    Hello. I am not sure if this is the correct place for this question. Please direct me if not. I am trying to set a webpage to redirect and display a different page if the first page is accessed from a mobile device (phone). Does anyone know how I can achieve this? I just need to know how to determine what it is viewed on. The redirect part I know already.

    Thanks so much for all help!

  • #2
    Regular Coder nomanic's Avatar
    Join Date
    Feb 2009
    Location
    United Kingdom
    Posts
    255
    Thanks
    9
    Thanked 33 Times in 33 Posts
    might be better doing this with php
    <DmncAtrny> I will write on a huge cement block "BY ACCEPTING THIS BRICK THROUGH YOUR WINDOW, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE INSTALLATION OF THIS BRICK INTO YOUR BUILDING."
    <DmncAtrny> And then hurl it through the window of a Sony officer
    <DmncAtrny> and run like hell

    Portfolio, Tutorials - http://www.nomanic.biz/

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,472
    Thanks
    0
    Thanked 634 Times in 624 Posts
    The simplest way would be to test the viewport width and redirect if the width is less than whatever you decide is the widest that you want to redirect.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Although generally you shouldn't redirect, because you have to deal with two versions of your site; have you considered simply styling the page differently?

  • #5
    New to the CF scene
    Join Date
    Jul 2012
    Location
    Sweden / Sverige
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you download this file and put it into your site and then put this into your index.php file:

    It needs to end with .php or else the script won't work
    PHP Code:
    require_once 'Mobile_Detect.php';
    $detect = new Mobile_Detect();
    if(
    $detect->isMobile() or $detect->isTablet()){
    header("Location: http://m.yoursite.com/");

    The script is not hard or complicated, if you reed it you would probably understand it clearly.

    This will redirect any mobiles or tablets to your mobile version of your site.

    More info on how you can use the Mobile_Detect.php file can be found here.

    Important notes:
    The file needs to be unzipped, and the content is going into your server.
    The demo.php file is not necessary, only the Mobile_Detect.php file.
    The Mobile_Detect.php file needs to be in the same directory as the file you put the script into.

  • #6
    Regular Coder
    Join Date
    Jul 2008
    Posts
    157
    Thanks
    9
    Thanked 13 Times in 13 Posts

    JS to refirect

    Think CSStricks.com featured this <script>

    Code:
    <meta name="viewport"  content="width=device-width, user-scalable=yes">
    
    <script type="text/javascript">
    <!--
    if (screen.width <= 699) {
    document.location = "indexmobile.html";
    }
    //-->
    </script>
    Question being: "Does mobile device support JavaScript?"

    Could add <nosript>If NO JavaScript, see indexmobile.httml</noscript>

    May be clunky, but works.

  • #7
    Regular Coder
    Join Date
    Jun 2011
    Location
    CA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by cjackson111 View Post
    Hello. I am not sure if this is the correct place for this question. Please direct me if not. I am trying to set a webpage to redirect and display a different page if the first page is accessed from a mobile device (phone). Does anyone know how I can achieve this? I just need to know how to determine what it is viewed on. The redirect part I know already.

    Thanks so much for all help!
    Some people use this to detect the kind of mobile phone is in use, and redirect to a different site:
    http://wurfl.sourceforge.net/index.php


  •  

    Posting Permissions

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