CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Building for mobile devices (http://www.codingforums.com/forumdisplay.php?f=70)
-   -   ...if viewed on a mobile phone (http://www.codingforums.com/showthread.php?t=249198)

cjackson111 01-18-2012 10:15 PM

...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!

nomanic 01-18-2012 11:16 PM

might be better doing this with php

felgall 01-19-2012 01:35 AM

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.

Apostropartheid 01-19-2012 12:31 PM

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?

kallejillheden 07-16-2012 10:03 PM

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.

waxdoc 07-16-2012 11:28 PM

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.

StevenHu 12-12-2012 10:18 PM

Quote:

Originally Posted by cjackson111 (Post 1182483)
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


All times are GMT +1. The time now is 10:53 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.