Help redirecting to mobile site

Joined
Feb 7, 2010
Messages
58
Reaction score
0
Points
6
Your Mac's Specs
MacBook Black 2.4 GHz Intel Core 2 Duo, 4GB 667 MHz DDR2 SDRAM 320gb 7200rpm HDD Snow Leopard
I have a portfolio site and am wanting to make it auto detect and redirect to the mobile version. I have a mobile version created but I am having trouble understanding how to do this. Any help is appreciated.
 
Joined
Nov 29, 2010
Messages
27
Reaction score
1
Points
3
Location
Vancouver, BC, Canada
Your Mac's Specs
Black 13.3" MacBook 4,1 Intel Core2 Duo, 4Gigs Ram (2x2G), 2.4GHz, OS X 10.7.2
Code:
<script type="text/javascript">// <![CDATA[
 var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
 if (mobile) { document.location = "http://www.youtube.com";}
// ]]></script>

The above code should redirect a mobile browser to youtube. So, just replace the youtube url with the url of your mobile site.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
If the above doesn't work, there's always the wonderful MooTools Browser class (see here) that can detect platform.

Take a look at this page I created a while back. All it does is print back some info about the browser and platform of the user using MooTools. It doesn't redirect but it does show how easy it is to use MooTools to do basic detection. Feel free to take what you need from the source.
 
OP
bassguy86
Joined
Feb 7, 2010
Messages
58
Reaction score
0
Points
6
Your Mac's Specs
MacBook Black 2.4 GHz Intel Core 2 Duo, 4GB 667 MHz DDR2 SDRAM 320gb 7200rpm HDD Snow Leopard
Code:
<script type="text/javascript">// <![CDATA[
 var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
 if (mobile) { document.location = "http://www.youtube.com";}
// ]]></script>

The above code should redirect a mobile browser to youtube. So, just replace the youtube url with the url of your mobile site.

I tried putting in the .mobi version of my site and it gave a "bad gateway" response. Is there a way I could put the path to the mobile folder on my server in the youtube spot and it work?
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
If you use DenAtTheDBM's solution, you will need to replace the YouTube URL with an appropriate path. How were you trying to do it?
 
OP
bassguy86
Joined
Feb 7, 2010
Messages
58
Reaction score
0
Points
6
Your Mac's Specs
MacBook Black 2.4 GHz Intel Core 2 Duo, 4GB 667 MHz DDR2 SDRAM 320gb 7200rpm HDD Snow Leopard
If you use DenAtTheDBM's solution, you will need to replace the YouTube URL with an appropriate path. How were you trying to do it?

I was replacing youtube.com with jonnypye.mobi should I use the mobile folder path under jonnypye.com instead? What would that be? index/mobile I would guess since the mobile folder is nested in the main directory. [Main folder/mobile]

EDIT: putting the mobile folder path worked! Thanks for the help!
 
OP
bassguy86
Joined
Feb 7, 2010
Messages
58
Reaction score
0
Points
6
Your Mac's Specs
MacBook Black 2.4 GHz Intel Core 2 Duo, 4GB 667 MHz DDR2 SDRAM 320gb 7200rpm HDD Snow Leopard
Now for a follow up question: Is there a way to put a link to full site that will bypass the auto redirect?
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top