Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Edward Knack
Courses Plus Student 3,351 PointsHow do i detect the state (NY, PA, or CT)of my web visitor? The Geobytes code I us works for desktops butnot smartphones
The code below works consistently on visitors on desktops but not always when I test on my smart phone. Do you know of a more reliable location detection code for smart phones? I don't want to know anything more about their location than the State they are in. I just want to redirect them to the website applicable to their State (NY, PA, or CT).
thanks for any help.
<!DOCTYPE html> <html> <head>
<title>test location </title>
</head>
<body>
<script src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesLocationCode,GeobytesCode,GeobytesInternet" language="Javascript"></script><script language="Javascript">// <![CDATA[ if(typeof(sGeobytesLocationCode)=="undefined" ||typeof(sGeobytesCode)=="undefined" ||typeof(sGeobytesInternet)=="undefined") { // Something has gone wrong with the variables, so set them to some default value, // maybe set a error flag to check for later on. var sGeobytesLocationCode="unknown"; var sGeobytesCode="unknown"; var sGeobytesInternet="unknown"; }
var thestate = sGeobytesLocationCode.substring(2, 4);
document.write(thestate);
if(thestate=="NY") {
window.location = "http://www.knacksite.com/ny/"
}else if(thestate=="PA")
{
window.location = "http://www.knacksite.com/pa/"
}
// ]]></script>
</body> </html>