d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Re-direct To A Subdomain > Re-directing
Add Reply New Topic New Poll
Member
Posts: 7,074
Joined: Jul 17 2007
Gold: 653.81
Mar 12 2013 09:10am
Hello,

I have a question about how/the best way to redirect to a subdomain.

However, i only want it to redirect to a subdomain when the site is accessed by a mobile device.

I have tried some things and they have not been working.

Ex.

<script type="text/javascript">
<!--
if (screen.width <= 700) {
window.location = "http://m.yourdomain.com";
}
//-->
</script>


I added this to the header tags of my html and it does not work when i test it...
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Mar 12 2013 10:04am
your code looks fine to me, but....

http://code.google.com/p/android/issues/detail?id=12455&q=javascriptwidth&colspec=IDTypeStatusOwnerSummaryStars

http://stackoverflow.com/questions/8508014/javascript-to-detect-mobile-browser-screen-width

a different method would be to examine their useragent string and see what browser they are using, although this would be messy

This post was edited by Azrad on Mar 12 2013 10:28am
Member
Posts: 7,074
Joined: Jul 17 2007
Gold: 653.81
Mar 12 2013 10:30am
Quote (Azrad @ Mar 12 2013 12:04pm)


ok thanks ill try that..

although, i was testing this on iOS.


I do remember in researching that an htaccess file code could be better for detecting a mobile device than javascript.
Member
Posts: 7,074
Joined: Jul 17 2007
Gold: 653.81
Mar 12 2013 11:41am
http://detectmobilebrowsers.com

I also found this.

I would think i would download the "javascript" one.

where would i place that code? it downloads as a text doc.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 12 2013 12:45pm
different ways to do this

you can use the meta refresh html code to handle this

<meta http-equiv="refresh" content="N; URL=other-web-address">

which is included in the head portion of your code. you can also use htaccess to do this via

Redirect /courses/2007spring/PHY386/index.html http://www.pa.msu.edu/people/username/subdir/index.htm

javascript isnt a very good way to handle this. and some portable web browsers and almost all normal browsers with noscript install block java and javascript on the spot.
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Mar 12 2013 06:01pm
Quote (AbDuCt @ Mar 12 2013 11:45am)
and some portable web browsers and almost all normal browsers with noscript install block java and javascript on the spot.
oh that's a good point

Go Back To Programming & Development Topic List
Add Reply New Topic New Poll