Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Mobile Marketing (https://www.warriorforum.com/mobile-marketing/)
-   -   Here is a free mobile device detect and redirect script for Warrior Buddies! (https://www.warriorforum.com/mobile-marketing/753020-here-free-mobile-device-detect-redirect-script-warrior-buddies.html)

bonn 12th February 2013 02:17 PM

Here is a free mobile device detect and redirect script for Warrior Buddies!
 
hey buddies,

Just shared this on someone else's thread, but im sure everyone could use it. Its used to detect mobile users on a desktop site and redirect them to a mobile site at a specific URL. Enjoy:

Just copy paste this code in between the <header>...</header> tags on the page you want to detect and redirect. Also change the "http://www.gomobileenterprise.com" to whatever your mobile site URL is.

;)

HTML Code:

<script>
function detect() {
      var uagent = navigator.userAgent.toLowerCase();
      var mobile = false;
      var search_strings = [
          "iphone",
          "ipod",
          "ipad",
          "series60",
          "symbian",
          "android",
          "windows ce",
          "windows7phone",
          "w7p",
          "blackberry",
          "palm"
      ];
      for (i in search_strings) {
          if (uagent.search(search_strings[i]) > -1) mobile = true;
      }
      return mobile;
  }
  if (detect()) window.location = "http://gomobileenterprise.com/";
</script>


Mr Bill 13th December 2013 08:37 PM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
What happens when a mobile visitor wants to see the full size website? Does this force them back to the mobile version in a loop?

adtastic 12th March 2014 10:06 PM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
Looks like would cause a loop. Also, try and keep up with all the kinds of phones. This is the script we use and think it is one of the best. Since it gives the user a choice of staying on the big site or going to the mobile site. It is based on screen size detection only. We use a size of 574 which should cover most smart phones and anything bigger is probably a tablet which would likely want the big site anyways. But still they would have the choice. And it doesn't cause a loop. If they decide they want to go back to the main site they can and it won't give them the message again. So very friendly. It does use JS but most have it these days. Should be placed just after the opening head tag.

<script type="text/javascript">
if (screen.width < 574) {
var ref = document.referrer;
var urls = new Array("http://www.yourbigwebsite.com","http://yourmobilewebsite.com");
var n = ref.match(urls[0]);
var m = ref.match(urls[1]);
if ((m!==null) || (n!==null)) {
stop;
}
else if (ref=='') {
var r = confirm("Small Display is Detected.\nClick \"OK\" for MOBILE SITE.");
if (r==true) {
window.location = "http://yourmobilewebsite.com";
}
else {
stop ;
}
}
else
{
window.location = "http://yourmobilewebsite.com";
}
}
</script>

Jay Moreno 13th March 2014 10:38 AM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
i would disagree php user agent detection in my opinion the best way to redirect visitors thats if you are using php of course, regardless if most phones are running javascript with php user agent detection not one single line of code needs to be rendered for the detection to kick in and redirect reduces overall page load speed - also certain earlier version of Android have issues with javascript screensize detection, there is actually a thread here on WF started by WillR specifically about that if i recall correctly. You will also find that 574px for newer smartphones will be way too low.

If you want to stick with javascript then why not do both javascript useragent detection and screensize detection... that way you have the best of both worlds.

FYI for the original script Bonn posted you will also need to add the user agent "bb" if you want the newer blackberries to be detected - since on newer devices the user agent no longer contains the word Blackberry. User agent for more recent Windows phone needs to be added too for the small handful of people using those devices! LOL

HTH

adtastic 13th March 2014 11:07 AM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
Hi Jay,
I don't disagree that what you say works. As to better, I suppose that simply depends on the person using it. My issue with php user agent detection is a couple of things. One is, the script I provided is to make it simple for people and not everyone is going to be using php or be into coding so this makes it simple.

The other problem I have with user agent detection and why we decided not to use that method is simply the need to always make sure you are up to date. Again, a reason for someone not all that technically savvy to not use it. because first you'd have to insure you have/know all known mobile user agents. Then you'd have to insure your script keeps up with any changes and as well figure out any potential unknowns. There are scripts on the internet for example you can use with apache or php or whatever that can help with that but again its simply another complication when we're just offering what is a simple and perhaps elegant solution.

As to screen size, arguably there are many different screen sizes. Perhaps our number isnt the perfect solution. It is simply based on all the research we did. We found that of the 10 most popular smartphones (eg most common) the largest screen size as of about late 2013 was 79mm. Which translates to 298 pixels. So I believe our number works at least for us since it is almost double that. I happen to have one of those "newer" smart phones with a large screen size and it works pretty good for me. But the beauty of the script, just modify the number if you don't agree or want larger screen sizes to redirect.
Too, if you want to strive for perfection, have a responsive web design as well. That way your main website will respond to smaller screen settings so if you don't redirect someone with a screen setting such as a large, large smartphone or tablet, chances are the responsive design scheme will serve them just the same.
You make a good point about using the two scripts that might be an idea. But you also confirm part of my argument when you mention that the original script in this thread needs user agent updating.
As to the js issue, well, hadn't thought abut that so you make a good point. I'll have to research that and see if it is a big enough issue to be concerned about and if so maybe we'll think of a solution to add to the code.
All in all though, we're probably saying the same thing just in different ways. :)

Jay Moreno 13th March 2014 12:44 PM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
Quote:

Originally Posted by adtastic (Post 9026651)
Hi Jay,
I don't disagree that what you say works. As to better, I suppose that simply depends on the person using it. My issue with php user agent detection is a couple of things. One is, the script I provided is to make it simple for people and not everyone is going to be using php or be into coding so this makes it simple.

The other problem I have with user agent detection and why we decided not to use that method is simply the need to always make sure you are up to date. Again, a reason for someone not all that technically savvy to not use it. because first you'd have to insure you have/know all known mobile user agents. Then you'd have to insure your script keeps up with any changes and as well figure out any potential unknowns. There are scripts on the internet for example you can use with apache or php or whatever that can help with that but again its simply another complication when we're just offering what is a simple and perhaps elegant solution.

As to screen size, arguably there are many different screen sizes. Perhaps our number isn't the perfect solution. It is simply based on all the research we did. We found that of the 10 most popular smartphones (eg most common) the largest screen size as of about late 2013 was 79mm. Which translates to 298 pixels. So I believe our number works at least for us since it is almost double that. I happen to have one of those "newer" smart phones with a large screen size and it works pretty good for me. But the beauty of the script, just modify the number if you don't agree or want larger screen sizes to redirect.
Too, if you want to strive for perfection, have a responsive web design as well. That way your main website will respond to smaller screen settings so if you don't redirect someone with a screen setting such as a large, large smartphone or tablet, chances are the responsive design scheme will serve them just the same.
You make a good point about using the two scripts that might be an idea. But you also confirm part of my argument when you mention that the original script in this thread needs user agent updating.
As to the js issue, well, hadn't thought abut that so you make a good point. I'll have to research that and see if it is a big enough issue to be concerned about and if so maybe we'll think of a solution to add to the code.
All in all though, we're probably saying the same thing just in different ways. :)

Unlike some scripts that include 1000's of pointless user agents if you take the time can easily group user agents under a common denominator - for example a user agent reference detecting iOS will detect all iPhones ever released... so no update required there in almost 7 years, same for the android, literally in the past 3 years the only major update really has been for the new Blackberry devices which since they dropped the "blackberry" reference in favor of BB on their newer models even Windows phones 7, 7.5 and 8 could have been group as well.

If the script had included the BB useragent which it really should have since the newer blackberries were available back then - there really would have been no reason to update the script since its posted which was actually over a year ago.

The biggest issue at the moment with user agent detection that i see is for accurate tablet detection particularly with Android devices - most people don't want to redirect tablets which is the approach we take however at the moment although a standard was placed for Android tablets to have a specific tablet user agent reference of "Android Mobile" many manufactures for whatever reason don't follow by these guidelines, particular cheaper Android Tablet manufacturers. I have even seen some Android tablets reflect iPad user agents - how crazy is that! Because of this many Android Tablets are wrongly considered to be Android smartphones that's why if a fall back was needed for screensize detection this would be it.

There is an online screensize checker site that you can test (can't recall name of it off top of my head) but i know for a fact you can literally check screensize on the Samsung S and perhaps the S2 when running "i think" Android 2.2 and below it will show bizarre and erratic sizes... sometimes +1300px wide!!!! This really highlights the concerns i have with screensize detection...

We prefer to use a RESS approach which displays responsive for tablets and desktop visitors, but instead of switching to a specific standalone mobile site we opt to render a totally different HTML layout thats optimized for mobile - however in order to do the switch the same base principles for user agent detection is used.

Hope that helps!

Jay

heyulin 16th March 2014 05:55 AM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
many thanks to your share~
take a try later

joe ferdinando 16th March 2014 07:09 AM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
Nice script

this is what I have been using:

Code:

<script type='text/javascript'>(function(a,b){if(/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|e-|e/|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(-|2|g)|yas-|your|zeto|zte-/i.test(a.substr(0,4)))window.location=b})(navigator.userAgent||navigator.vendor||window.opera,'http://yoursite.com');</script>

Jay Moreno 16th March 2014 02:13 PM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
Quote:

Originally Posted by joe ferdinando (Post 9033146)
Nice script

this is what I have been using:

Code:

<script type='text/javascript'>(function(a,b){if(/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|e-|e/|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(-|2|g)|yas-|your|zeto|zte-/i.test(a.substr(0,4)))window.location=b})(navigator.userAgent||navigator.vendor||window.opera,'http://yoursite.com');</script>

Joe, a quick scan over your useragents and i dont see one for the newer blackberry devices ie bb

The new blackberries don't have "blackberry" in their user agent anymore... see the following...

Mozilla/5.0 (BB10; <Device Model>) AppleWebKit/<WebKit Version> (KHTML, like Gecko) Version/<BB Version #> Mobile Safari/<WebKit Version>

Also a lot of the useragents are relatively redundant too as they mainly refer to useragents that predate feature phones ie the old school flip phones, and wap phones etc also I don't see anything for the ipod touch either. Also with your script it doesn't look like you have any implementation to allow the mobile visitor to return back to the desktop site from the mobile site - ie it will simply return them back to the mobile site in a constant loop each time they click "view desktop". Haven't tested your script but these are just quick observations.

hope that helps

jay

joe ferdinando 16th March 2014 03:49 PM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
Quote:

Originally Posted by Jay Moreno (Post 9034039)
Joe, a quick scan over your useragents and i dont see one for the newer blackberry devices ie bb

The new blackberries don't have "blackberry" in their user agent anymore... see the following...

Mozilla/5.0 (BB10; <Device Model>) AppleWebKit/<WebKit Version> (KHTML, like Gecko) Version/<BB Version #> Mobile Safari/<WebKit Version>

Also a lot of the useragents are relatively redundant too as they mainly refer to useragents that predate feature phones ie the old school flip phones, and wap phones etc also I don't see anything for the ipod touch either. Also with your script it doesn't look like you have any implementation to allow the mobile visitor to return back to the desktop site from the mobile site - ie it will simply return them back to the mobile site in a constant loop each time they click "view desktop". Haven't tested your script but these are just quick observations.

hope that helps

jay

Jay thanks for your tips. I have and use other redirect script. The one I posted seems to work well. I have no negative feedback yet. But I will look at your suggestions and update the script. Thank you once again!

Also what script are you using? can you share it here?

I seen your post on php script, can you share it?

Nurkholis Hidayat 16th March 2014 06:30 PM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
thanks for your share. I'll bookmark it first, try it later

Jay Moreno 17th March 2014 12:50 PM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
@joe - i use our own redirect plugin for WP but for when i have to use a javascript version on a standard site i typically use this one:

https://github.com/sebarmeli/JS-Redirection-Mobile-Site

hth

wapi 17th March 2014 02:19 PM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
Well! When you are redirected to mobile site, the mobile site will have a redirection link to full site whenever the users wants to get to full site. It can be done my a footer link that takes visitors to full site.

Jay Moreno 18th March 2014 10:49 AM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
Quote:

Originally Posted by wapi (Post 9036702)
Well! When you are redirected to mobile site, the mobile site will have a redirection link to full site whenever the users wants to get to full site. It can be done my a footer link that takes visitors to full site.

And how exactly do you propose to stop the main desktop site from redirecting the returning visitor back to the mobile site?

Typically this is done with a cookie/session control - it just doesn't do it auto-magically...

Toby Henderson 21st March 2014 03:57 AM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
P.M. me if you want a Free Mobile Site Builder... I am your real internet buddy notice how many advertisements below... zero yes its Christmas early today and this one comes with the script... I will send you a zip file if you like it which you will just add me as a friend here in the WF. I have built sites out with it and its very easy. It even comes with video setup and redirect and wordpress install or regular site doesn't matter. Your site will pick up mobile users and redirect them to a separate nice looking mobile optimized site... built in php so it passes data and is real quick set up...

nikolas22t 24th November 2014 11:30 AM

Re: Here is a free mobile device detect and redirect script for Warrior Buddies!
 
Is there any way to redirect based on mobile model ?

On logs i can see

"LG-D802",
"Nexus 5"


All times are GMT -6. The time now is 02:09 AM.