After exploring various options, I eventually decided to implement a rather unconventional solution that utilizes media queries and the getComputedStyle
method to automatically redirect users to a mobile site if they are browsing from an iPhone-like device.
<style media="only screen and (max-device-width: 480px)">html{border-top-style:dashed;}</style>
<script>
if(window.location.search.indexOf("?m=t")==-1 && window.getComputedStyle) {
var mobile = false;
if(window.getComputedStyle(document.getElementsByTagName("html")[0],null).getPropertyValue("border-top-style")=="dashed") {
var mobile = true;
}
if(mobile) {
window.location.replace(window.location+"?m=t");
}
}
</script>
I remember coming across the concept of using getComputedStyle
on Stack Overflow, although the exact source eludes me at the moment.