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

by bonn 15 replies
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 "" to whatever your mobile site URL is.

HTML Code:
function detect() {
       var uagent = navigator.userAgent.toLowerCase();
       var mobile = false;
       var search_strings = [
           "windows ce",
       for (i in search_strings) {
           if ([i]) > -1) mobile = true;
       return mobile;
   if (detect()) window.location = "";
#mobile marketing #buddies #detect #device #free #mobile #redirect #script #warrior
Avatar of Unregistered
  • Profile picture of the author BiggestB

    Finally, An Automated Forex Trading Robot That Actually Makes sense! Free Forex Trading Robot

  • Profile picture of the author netizen
    Netizen Pros - Marketing & Advertising
  • Profile picture of the author Mr Bill
    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?
    • Profile picture of the author adtastic
      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("","");
      var n = ref.match(urls[0]);
      var m = ref.match(urls[1]);
      if ((m!==null) || (n!==null)) {
      else if (ref=='') {
      var r = confirm("Small Display is Detected.\nClick \"OK\" for MOBILE SITE.");
      if (r==true) {
      window.location = "";
      else {
      stop ;
      window.location = "";
    • Profile picture of the author wapi
      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.

      In order to succeed, your desire for success should be greater than your fear of failure.

  • Profile picture of the author Jay Moreno
    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

    Sorry, I am too busy helping people to think of a cool signature!
    • Profile picture of the author adtastic
      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.
  • Profile picture of the author Moneymaker2012
  • Profile picture of the author heyulin
    many thanks to your share~
    take a try later
    • Profile picture of the author joe ferdinando
      Nice script

      this is what I have been using:

      <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,'');</script>
  • Profile picture of the author Jay Moreno
    @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:

    Sorry, I am too busy helping people to think of a cool signature!
  • Profile picture of the author Toby Henderson
    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...
  • Profile picture of the author israrahmed

Trending Topics