Link to home
Start Free TrialLog in
Avatar of Hocke_sweden
Hocke_sweden

asked on

Change detect mobile browser

I have a javascript  to detect moible browser, but I want to change script from
mdetect.js to detectmobilebrowser.js but  can't get it to work.

Can someone help me?

The script check if its a mobile browser and then redirect the to a mobile webb page, but if the webb address is for example www.aftonbladet.se?frMobilsajten


<script type="text/javascript" src="mdetect.js"></script>

 <script type="text/javascript">
 	frMobilsajt = window.location.search.substring(1);
 	
	var mobil=getCookie("mobil");
	if (mobil==null || mobil=="" || mobil == "undefined")
	{

 
	    if (DetectTierIphone()) {  
			var exdate=new Date();
			// exdate.setDate(exdate.getDate() + 1) 
		    exdate.setMinutes( exdate.getMinutes() + 5)
			document.cookie="mobil=ja;expires="+exdate.toUTCString();
		 	if (frMobilsajt!="frMobilsajten")
		 	{
		        document.location = "http://m.aftonbladet.se";  
	        }
	    }  
	}
	
	else
	{
			//document.cookie="mobil='nej';expires=Thu, 01-Jan-70 00:00:01 GMT;";
	}
	

	
	function getCookie(c_name)
	{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
	  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
	  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
	  x=x.replace(/^\s+|\s+$/g,"");
	  if (x==c_name)
	    {
	    return unescape(y);
	    }
	  }
	}
</script>

Open in new window

mdetect.js
detectmobilebrowser.js
SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hocke_sweden
Hocke_sweden

ASKER

I have change mdetect.js to detectmobilebrowser.js, but detectmobilebrowser.js don't work toghter with
the code: frMobilsajt = window.location.search.substring(1);....

But I want both detect browser and cookies, not only detect!
        
I try to be a little bit clearer

The script
<script type="text/javascript" src="detectmobilebrowser.js"></script> works alone but not with
the rest of the code

The script
<script type="text/javascript" src="mdetect.js"></script> works with the rest of the code


detectmobilebrowser and mdetect do the same= they detect, but I cant get detectmobilebrowser.js to work togheter with cookie script :)
It was not a solution