Solved

Change detect mobile browser

Posted on 2011-09-06
6
1,174 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:Hocke_sweden
6 Comments
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 166 total points
ID: 36487817
Don't think that you need a separate script for browser detection
this link has most mobile's user agents
http://www.zytrax.com/tech/web/mobile%5Fids.html

so, check which one is which, and do the redirect accordingly

a sample is

var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
    if (mobile) {
        document.location = "http://www.yoursite.com/mobile.html";
    }
0
 
LVL 14

Accepted Solution

by:
R-Byter earned 167 total points
ID: 36487823
One stupid question from me, did You change this line:

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

Open in new window


to this:

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

Open in new window


Regards
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 167 total points
ID: 36487876
you need replace all the scriptS (from line 1 to line 44) you put in your question by :
<script type="text/javascript" src="detectmobilebrowser.js"></script>

open to edit detectmobilebrowser.js to change the addresses
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Hocke_sweden
ID: 36488348
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!
        
0
 

Author Comment

by:Hocke_sweden
ID: 36488369
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 :)
0
 

Author Closing Comment

by:Hocke_sweden
ID: 37005387
It was not a solution
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question