Go Back   CodingForums.com > :: Client side development > General web building > Building for mobile devices

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-18-2012, 10:15 PM   PM User | #1
cjackson111
New to the CF scene

 
Join Date: Jul 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
cjackson111 is an unknown quantity at this point
...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!
cjackson111 is offline   Reply With Quote
Old 01-18-2012, 11:16 PM   PM User | #2
nomanic
Regular Coder

 
nomanic's Avatar
 
Join Date: Feb 2009
Location: United Kingdom
Posts: 252
Thanks: 9
Thanked 33 Times in 33 Posts
nomanic is an unknown quantity at this point
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/
nomanic is offline   Reply With Quote
Old 01-19-2012, 01:35 AM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Old 01-19-2012, 12:31 PM   PM User | #4
Apostropartheid
The Apostate


 
Apostropartheid's Avatar
 
Join Date: Oct 2007
Posts: 3,215
Thanks: 16
Thanked 265 Times in 263 Posts
Apostropartheid is on a distinguished road
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?
__________________
Blog | Twitter
Useful links: W3C HTML Validator | W3C CSS Validator | HTML 5 Guide
CF: HTML & CSS Resources/Tutorials Thread | HTML & CSS Posting Rules and Guidelines
Remember: no link, no code, no help!
Apostropartheid is offline   Reply With Quote
Old 07-16-2012, 10:03 PM   PM User | #5
kallejillheden
New to the CF scene

 
Join Date: Jul 2012
Location: Sweden / Sverige
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
kallejillheden is an unknown quantity at this point
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.
kallejillheden is offline   Reply With Quote
Old 07-16-2012, 11:28 PM   PM User | #6
waxdoc
Regular Coder

 
Join Date: Jul 2008
Posts: 155
Thanks: 9
Thanked 13 Times in 13 Posts
waxdoc is an unknown quantity at this point
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.
waxdoc is offline   Reply With Quote
Old 12-12-2012, 10:18 PM   PM User | #7
StevenHu
Regular Coder

 
Join Date: Jun 2011
Location: CA
Posts: 105
Thanks: 0
Thanked 10 Times in 10 Posts
StevenHu is an unknown quantity at this point
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
__________________
Steve Husting
http://iphonedevlog.wordpress.com
StevenHu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:59 AM.


Advertisement
Log in to turn off these ads.