12th Feb 2013, 02:17 PM | #1 |
Mobile Site Wizzard! War Room Member Join Date: 2010 Location: Scottsdale / Santa Monica
Posts: 174
Thanks: 4
Thanked 36 Times in 22 Posts
|
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> |
| |
The Following 6 Users Say Thank You to bonn For This Useful Post: |
13th Dec 2013, 08:37 PM | #2 |
VIP Warrior War Room Member Join Date: 2011
Posts: 1,633
Thanks: 1,211
Thanked 952 Times in 497 Posts
|
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?
|
12th Mar 2014, 10:06 PM | #3 |
Warrior Member Join Date: 2011
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
|
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> |
13th Mar 2014, 10:38 AM | #4 |
Mobile+WP = JumpMobi.com War Room Member Join Date: 2009 Location: San Antonio, Tx
Posts: 1,271
Thanks: 301
Thanked 449 Times in 309 Posts
|
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 |
Sorry, I am too busy helping people to think of a cool signature! | |
13th Mar 2014, 11:07 AM | #5 |
Warrior Member Join Date: 2011
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
|
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. |
13th Mar 2014, 12:44 PM | #6 | |
Mobile+WP = JumpMobi.com War Room Member Join Date: 2009 Location: San Antonio, Tx
Posts: 1,271
Thanks: 301
Thanked 449 Times in 309 Posts
|
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 | |
Sorry, I am too busy helping people to think of a cool signature! | ||
16th Mar 2014, 05:55 AM | #7 |
Warrior Member Join Date: 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
many thanks to your share~ take a try later |
16th Mar 2014, 07:09 AM | #8 |
Ferdiworks Warrior War Room Member Join Date: 2005 Location: Spring Hill, FL , USA.
Posts: 590
Thanks: 82
Thanked 450 Times in 283 Posts
|
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> |
| |
The Following User Says Thank You to joe ferdinando For This Useful Post: |
16th Mar 2014, 02:13 PM | #9 | |
Mobile+WP = JumpMobi.com War Room Member Join Date: 2009 Location: San Antonio, Tx
Posts: 1,271
Thanks: 301
Thanked 449 Times in 309 Posts
|
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 | |
Sorry, I am too busy helping people to think of a cool signature! | ||
16th Mar 2014, 03:49 PM | #10 | |
Ferdiworks Warrior War Room Member Join Date: 2005 Location: Spring Hill, FL , USA.
Posts: 590
Thanks: 82
Thanked 450 Times in 283 Posts
|
Also what script are you using? can you share it here? I seen your post on php script, can you share it? | |
| ||
16th Mar 2014, 06:30 PM | #11 |
HyperActive Warrior Join Date: 2012 Location: Indonesia
Posts: 116
Thanks: 35
Thanked 28 Times in 24 Posts
|
thanks for your share. I'll bookmark it first, try it later
|
17th Mar 2014, 12:50 PM | #12 |
Mobile+WP = JumpMobi.com War Room Member Join Date: 2009 Location: San Antonio, Tx
Posts: 1,271
Thanks: 301
Thanked 449 Times in 309 Posts
|
@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 |
Sorry, I am too busy helping people to think of a cool signature! | |
17th Mar 2014, 02:19 PM | #13 |
Desire for Success Join Date: 2013 Location: India
Posts: 27
Thanks: 18
Thanked 5 Times in 5 Posts
|
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. CouponStock.net | |
18th Mar 2014, 10:49 AM | #14 | |
Mobile+WP = JumpMobi.com War Room Member Join Date: 2009 Location: San Antonio, Tx
Posts: 1,271
Thanks: 301
Thanked 449 Times in 309 Posts
|
Typically this is done with a cookie/session control - it just doesn't do it auto-magically... | |
Sorry, I am too busy helping people to think of a cool signature! | ||
21st Mar 2014, 03:57 AM | #15 |
Warrior Member War Room Member Join Date: 2010 Location: USA
Posts: 19
Thanks: 23
Thanked 12 Times in 6 Posts
|
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...
|
24th Nov 2014, 11:30 AM | #16 |
Warrior Member Join Date: 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
Is there any way to redirect based on mobile model ? On logs i can see "LG-D802", "Nexus 5" |
Bookmarks |
Tags |
buddies, detect, device, free, mobile, redirect, script, warrior |
Thread Tools | Search this Thread |
| |