Hi Brian,
This has been driving me nuts all weekend so I've been doing lots of digging around online and I think I've cracked the cookie solution. I've tried it on my mobile site and all seems good so far. Please have a look and see if it works for you:
www.dotted-line.mobi
The first time you visit the site it should ask if you want to be re-directed if you view the site from a normal sized PC. After that first visit it shouldn't ask the question again if you visit the page within 1 day. (I just picked 1 day as it suited me). I've left a test button lower down the page to delete the cookie. I'll remove this once I'm satisfied it all works properly. The code is below if you're interested;
The following is pasted into an html fragment - paste to header - ignore page position:
<script>
function getCookie(NameOfCookie){
if (document.cookie.length > 0) {
begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1) {
begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end));
}
}
return null;
}
function setCookie(NameOfCookie, value, expiredays) {
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
function delCookie (NameOfCookie) {
if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
function DoTheCookieStuff()
{
visited=getCookie('visited');
if (visited==null)
{
setCookie('visited','yes',1)
if (screen.width >= 640) {if (confirm("This is the mobile version. Do you want to go to the full size site?")) document.location = "http://www.myfullsizewebsite.com";}
}
}
</script>
The following is then pasted into the body of the same html fragment:
<body onLoad="DoTheCookieStuff()">
If you want the cookie to last for longer then change the number 1 in the line:
setCookie('visited','yes',1)
so for the cookie to expire in a year it would be:
setCookie('visited','yes',365)
I think I've grasped the basics but don't pretend to know anything much about cookies at all - it was trial and error on my part!
Hope this helps make the screen width test more usable. Thanks again for your help.
David.