Navigation

10/22/2012

Detect mobile device via Javascript, switch to mobile page


Our CMS is looks poor on mobile drives, looked at javascript to switch to a different page on detecting mobile device:


<script type="text/javascript">
var mobile = (/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|iphone|ipod|iris|kindle|lge|maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent.toLowerCase()));
if (mobile){ document.writeln("<h2>
<a href='http://your.server.com/m.asp?insert_room=1'>Tap here for MOBILE version...</a></h2>
");
 
    }

</script>


I replaced the document switch:
document.location = 'http://your.server.com/m/'

with just adding a link to a different page:
document.writeln("<h2>
<a href='http://your.server.com/m.asp?insert_room=1'>Tap here for MOBILE version...</a></h2>

No comments:

Post a Comment