Solved

Change detect mobile browser

Posted on 2011-09-06
6
1,149 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now