Solved

Change detect mobile browser

Posted on 2011-09-06
6
1,188 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get total count of passed in subject based on marks? 7 32
jQuery Datatables.js Selecting a Row to get ID 5 36
Wordpress and Wufoo 1 37
Html split(text) Part2 6 20
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

740 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