Thursday, May 9, 2013

JavaScript to redirect to a smart phone formatted page


This little script, placed between the <head> </head> tags will redirect to a different page if the user's screen size is less than 699 pixels wide. This is useful if your normal web page has, for example, two or more columns, which don't display well on a small screen, or other content that does not work well on a smart phone. I recommend creating a single column page with basic information and font size in ems or percentage so that it is readable for the resulting page.

<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "http://www.your_mobile_webpage.html";
}
//-->
</script>