Article

How to Redirect Your Site to a Mobile Version Using JavaScript

12 Jun 2015 Kamal Pratap
0 Comments 1533 Views



Sometimes we need to redirect website to to the mobile version of the site. Below we explain the javascript code to redirect website to mobile site.

Put the following code in the head section of the website homepage.

<script language="javascript" type="text/javascript">
function mobile(){
	var redirectagent = navigator.userAgent.toLowerCase();
	var redirect_devices = ['vnd.wap.xhtml+xml', 'sony', 'symbian', 'nokia', 'samsung', 'mobile', 'windows ce', 'epoc', 'opera mini', 'nitro', 'j2me', 'midp-', 'cldc-', 'netfront', 'mot', 'up.browser', 'up.link', 'audiovox', 'blackberry', 'ericsson', 'panasonic', 'philips', 'sanyo', 'sharp', 'sie-', 'portalmmm', 'blazer', 'avantgo', 'danger', 'palm', 'series60', 'palmsource', 'pocketpc', 'smartphone', 'rover', 'ipaq', 'au-mic', 'alcatel', 'ericy', 'vodafone', 'wap1', 'wap2', 'teleca', 'playstation', 'lge', 'lg-', 'iphone', 'android', 'htc', 'dream', 'webos', 'bolt', 'nintendo'];
	for (var i in redirect_devices) {
		if (redirectagent.indexOf(redirect_devices[i]) != -1)
		{
			location.replace("http://m.mobilesite.com/");
		}
	}
}

window.onload=mobile();
</script>

 

Kamal Pratap

I have 6+ years experience in .Net technologies like Asp.Net, C#, WCF, Web Services, SQL Server, Ajax, LinQ. Currently I am working in Netcarrots Loyalty Services as a Software Developer.

Comments

No coments found to display!

Leave a Comment