Solved

Change detect mobile browser

Posted on 2011-09-06
6
1,194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

738 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