21st Feb 2012, 01:08 PM | #1 |
Mobile+WP = JumpMobi.com War Room Member Join Date: 2009 Location: San Antonio, Tx
Posts: 1,270
Thanks: 301
Thanked 449 Times in 309 Posts
|
Any of you that have read my previous posts will know I am not a big fan of Javascript screensize detect and redirect for mobile devices instead i prefer to use PHP user agent detection... However i know a lot of people here on WF do use Javascript based screen size detect and redirect... one of the biggest issues with that is many of the new Androids don't get the screen size detected properly and as a result many Android visitors are not getting redirected to your mobile site! Well despite me not liking that type of redirection i still don't want you missing out on your mobile visitors - so i have a fix for you Replace http://www.yourdomainhere.com with the domain you want to redirect your mobile visitor too HTML Code: <script type="text/javascript"> if (screen.width < 1024 || navigator.userAgent.toLowerCase().indexOf('android')!=-1) (window.location.replace("http://www.yourdomainhere.com")); </script> Place the code before your </head> tag in your html code. Hope that helps! But remember... 1) Google mobile bot will not be redirected to your site using this method 2) As mobile screen sizes become bigger this will become less effective. Cheers, Jay |
Sorry, I am too busy helping people to think of a cool signature! | |
The Following 3 Users Say Thank You to Jay Moreno For This Useful Post: |
21st Feb 2012, 04:15 PM | #2 | |
Active Warrior War Room Member Join Date: 2010 Location: Sunny Riviera
Posts: 94
Thanks: 49
Thanked 18 Times in 15 Posts
|
Probably a very stupid question but.... can I use this code beside another one, so that also Google bots are redirected to the mobile site? | |
21st Feb 2012, 07:40 PM | #3 | |
Mobile+WP = JumpMobi.com War Room Member Join Date: 2009 Location: San Antonio, Tx
Posts: 1,270
Thanks: 301
Thanked 449 Times in 309 Posts
|
hope that helps cheers jay | |
Sorry, I am too busy helping people to think of a cool signature! | ||
22nd Feb 2012, 01:10 AM | #4 |
You reap what you sow. War Room Member Join Date: 2008 Location: Sometimes you don't.
Posts: 1,078
Thanks: 196
Thanked 411 Times in 243 Posts
|
Jay, thanks for the Android addition but that code will also redirect desktop users with a screen width less than 1024px. And pixel is not a physical measure; when you change your screen resolution to 800x600 on a large screen, then the software will read its width as 800px. I wouldn't recommend screen size based redirection in any case. Here is a user-agent based JavaScript redirection that I have been using: Code: http://www.sebastianoarmelibattana.com/projects/js-redirection |
22nd Feb 2012, 10:32 AM | #5 |
Happy in Acuña War Room Member Join Date: 2008 Location: Dallas
Posts: 2,085
Thanks: 263
Thanked 650 Times in 515 Posts
Blog Entries: 2 |
Thanks Jay! Hope all is well for you and the family. Do you have recommendation for a script (php or java) that will handle the search engine bots? Want to make sure they find the clients mobile sites. Terry |
| |
22nd Feb 2012, 10:42 AM | #6 | |
Mobile+WP = JumpMobi.com War Room Member Join Date: 2009 Location: San Antonio, Tx
Posts: 1,270
Thanks: 301
Thanked 449 Times in 309 Posts
|
Nail am with you as i mentioned before i am NOT a fan of screen size redirection never have never will be! i personally use our own Wordpress Plugin based on PHP user agent detection or hard coded PHP useragent solution - our Wordpress doesnt just redirect it does a host of other things that you configure that most other solutions simply don't offer. Reason i posted this code is a lot of people on the WF do you use this type of simple redirect script... the javascript version is probably one of the most basic ones and simplest to deploy - problem is I get a lot of people asking be about the problems they have with this and it not redirecting certain Android devices... i am really not too bothered what screensize you pick thats down to personal preference as we have both mentioned before i wouldn't personal use this! lol ... but for those that want to or have to its very simple to edit 1024 to 799 or whatever you like... thing is screen sizes resolution on mobile devices are constantly increasing... some mobile devices have resolutions over 800 now and stats show its very rare you will get a desktop screen size less than 1024 - resizing your browser window is another matter... Using this modified javascript will certainly help anyone who was having issues before with their previous version and android not redirecting it also gives me a reference point to show people who ask me about it... literally the main reason why i took the time to come up with a solution. Bottom line for me is use PHP useragent detection where possible - it's much more reliable, it will redirect google's mobile bot if configured correctly - second preference i guess would be .htaccess and then lastly this. User agent detection can be used for many things more than just redirect... it's your friend read up on it - it can certainly help for a better mobile user experience! | |
Sorry, I am too busy helping people to think of a cool signature! | ||
22nd Feb 2012, 10:55 AM | #7 | |
Mobile+WP = JumpMobi.com War Room Member Join Date: 2009 Location: San Antonio, Tx
Posts: 1,270
Thanks: 301
Thanked 449 Times in 309 Posts
|
If you have you own PHP script thats doing user agent detection take a look at this page and ensure you script is detecting both the google mobile bots... Official Google Webmaster Central Blog: Introducing smartphone Googlebot-Mobile REMEMBER though.... unless your site actually validates correctly Google will not consider it mobile and will place your site in the same pool as regular desktop sites.... i have wrote extensively on WF about this particular subject so wont go into too much detail repeating myself here but its worth reading up on to understand the value of validation, and speed. I think both of these will become even more important factors in Mobile Web in the next 18 months. FYI - From my understanding Google will ignore ANY javascript based redirection script. | |
Sorry, I am too busy helping people to think of a cool signature! | ||
22nd Feb 2012, 07:33 PM | #8 | ||
Digital Marketer War Room Member Join Date: 2010 Location: Australia
Posts: 12,475
Thanks: 1,984
Thanked 8,187 Times in 4,079 Posts
|
It's also worth pointing out that the current statistics show that less than 1% of desktop users have a screen resolution of less than 1024, so I don't see this as a big problem. Browser Display Statistics
Creating and submitting a Google Mobile sitemap will take care of this for you. This should be standard practice for any sites you create whether mobile or standard. | ||
| |||
22nd Feb 2012, 08:55 PM | #9 |
HyperActive Warrior War Room Member Join Date: 2011 Location: North of Birmingham, AL
Posts: 109
Thanks: 20
Thanked 23 Times in 23 Posts
|
I still like the idea of instead of a redirect to simply have it read a different CSS file to render the page. something like: If size is less than 600 load mobile.css, if size is 600 >= 1024 load tablet.css, else if > 1024 px load site.css It gives you more control over the site. Suzanne |
22nd Feb 2012, 11:36 PM | #10 | |
Digital Marketer War Room Member Join Date: 2010 Location: Australia
Posts: 12,475
Thanks: 1,984
Thanked 8,187 Times in 4,079 Posts
|
| |
| ||
23rd Feb 2012, 03:49 PM | #12 | |
Ultimate Warrior Join Date: 2011
Posts: 734
Thanks: 28
Thanked 181 Times in 131 Posts
|
The Redirect Script needs to be before the </HEAD> Tag, as he said, but make sure it is AFTER the <HEAD> Tag and BEFORE the </HEAD> Tag or it will not work properly. | |
(916) 520-HYPE (4973) Local & Mobile Marketing Solutions $0 Setup & $99/mnth Private Label Reseller Accts | ||
23rd Feb 2012, 04:27 PM | #13 |
HyperActive Warrior War Room Member Join Date: 2011 Location: North of Birmingham, AL
Posts: 109
Thanks: 20
Thanked 23 Times in 23 Posts
| |
24th Feb 2012, 12:16 AM | #14 | |
Warrior Member Join Date: 2011
Posts: 12
Thanks: 3
Thanked 8 Times in 5 Posts
|
The content that gets downloaded needs to really be decided server-side, before anything gets downloaded. But you can mix both ways. I currently use css to control display and switch some content (content that would be a very small download). I use a server-side method for images and for other large content, I design creatively. Designing for mobile first makes this a bit easier. Look at Adaptive Images or TinySrc for some reasonably simple to implement image solutions. | |
24th Feb 2012, 05:38 AM | #15 |
Digital Marketer War Room Member Join Date: 2010 Location: Australia
Posts: 12,475
Thanks: 1,984
Thanked 8,187 Times in 4,079 Posts
| |
| |
19th Apr 2012, 09:16 AM | #16 |
Warrior Member Join Date: 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
[QUOTE= <script type="text/javascript"> if (screen.width < 1024 || navigator.userAgent.toLowerCase().indexOf('android ')!=-1) (window.location.replace("http://www.yourdomainhere.com")); </script> [/QUOTE] Thank you very much Jay, this script seems to work properly, while the many others that I have tested had some problems :- ) |
Bookmarks |
Tags |
android, issues, javascript, mobile, redirect, redirection, screensize |
| |