Reputation: 33
I have made a website with HTML and Javascript. When someone goes on the full site with an iPhone or iPod Touch it redirects them. The problem is that I have a link on my mobile one to go back to the full site which doesn't work because it just redirects them back to the mobile site. Any help would be appreciated.
The javascript to redirect:
<script language=javascript>
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
location.replace("Mobile version");
}
-->
</script>
Upvotes: 0
Views: 161
Reputation: 3558
Add a cookie when the user selects to go to the full site. Then in your redirect to mobile check to make sure that cookie doesn't exist.
To set the cookie:
var expire = new Date();
expire.setTime(expire.getTime()+(1*24*60*60*1000));
document.cookie = "nomobile=true; expires="+expire+"; path=/";
To read the cookie:
function getCookie(c_name) {
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++) {
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name) {
return unescape(y);
}
}
}
if (!getCookie("nomobile")) {
//USE THIS AREA TO CHECK THE USER AGENT AND REDIRECT AS YOU CURRENTLY ARE
}
Upvotes: 1
Reputation: 81916
One simple fix would be to check if the referrer is your own website. It your coming from your own site, then don't redirect to the mobile version.
Upvotes: 0