How to add your Mobile Redirect?

What is a Mobile Redirect?

It’s a simple script you add to your desktop website that can tell when someone is visiting from a phone and will automatically redirect them to your mobile website.

<script src="DM_redirect.js" type="text/javascript"></script>
<script type="text/javascript">DM_redirect("http://m.cdl.gr");</script>

 

function DM_redirect(MobileURL, Home){
	try {
		// avoid loops within mobile site
		if(document.getElementById("dmRoot") != null)
		{
			return;
		}
		var CurrentUrl = location.href
		var noredirect = document.location.search;
		if (noredirect.indexOf("no_redirect=true") < 0){
			if ((navigator.userAgent.match(/(iPhone|iPod|BlackBerry|Android|webOS|Windows CE|IEMobile|Opera Mini|Opera Mobi|HTC|LG-|LGE|SAMSUNG|Samsung|SEC-SGH|Symbian|Nokia|PlayStation|PLAYSTATION|Nintendo DSi)/i)) ) {
				
				if(Home){
					location.replace(MobileURL);
				}
				else
				{
					location.replace(MobileURL + "?url=" + encodeURIComponent(CurrentUrl));
				}
			}
		}	
	}
	catch(err){}
}

Leave a comment