Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 21st Feb 2012, 01:08 PM   #1
Mobile+WP = JumpMobi.com
War Room Member
 
Jay Moreno's Avatar
 
Join Date: 2009
Location: San Antonio, Tx
Posts: 1,270
Thanks: 301
Thanked 449 Times in 309 Posts
Default
LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

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>
With this code implemented it will redirect visitors with screen sizes smaller than 1024 and also ALL your android visitors.

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!
Jay Moreno is offline  
The Following 3 Users Say Thank You to Jay Moreno For This Useful Post:
Unread 21st Feb 2012, 04:15 PM   #2
Active Warrior
War Room Member
 
danifae's Avatar
 
Join Date: 2010
Location: Sunny Riviera
Posts: 94
Thanks: 49
Thanked 18 Times in 15 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

Originally Posted by Jay Moreno View Post

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
Thank you for the code!
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?
danifae is offline  
Unread 21st Feb 2012, 07:40 PM   #3
Mobile+WP = JumpMobi.com
War Room Member
 
Jay Moreno's Avatar
 
Join Date: 2009
Location: San Antonio, Tx
Posts: 1,270
Thanks: 301
Thanked 449 Times in 309 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

Originally Posted by danifae View Post

Thank you for the code!
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?
you could but not with javascript, it would need to be php based or done with a .htaccess file - you need to create a 301 redirect for the google mobilbot...

hope that helps

cheers

jay

Sorry, I am too busy helping people to think of a cool signature!
Jay Moreno is offline  
Unread 22nd Feb 2012, 01:10 AM   #4
You reap what you sow.
War Room Member
 
Nail Yener's Avatar
 
Join Date: 2008
Location: Sometimes you don't.
Posts: 1,078
Thanks: 196
Thanked 411 Times in 243 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

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
Nail Yener is offline  
Unread 22nd Feb 2012, 10:32 AM   #5
Happy in Acuña
War Room Member
 
Terry Jett's Avatar
 
Join Date: 2008
Location: Dallas
Posts: 2,085
Thanks: 263
Thanked 650 Times in 515 Posts
Blog Entries: 2
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

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

Terry Jett is offline  
Unread 22nd Feb 2012, 10:42 AM   #6
Mobile+WP = JumpMobi.com
War Room Member
 
Jay Moreno's Avatar
 
Join Date: 2009
Location: San Antonio, Tx
Posts: 1,270
Thanks: 301
Thanked 449 Times in 309 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

Originally Posted by Nail Yener View Post

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.

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!
Jay Moreno is offline  
Unread 22nd Feb 2012, 10:55 AM   #7
Mobile+WP = JumpMobi.com
War Room Member
 
Jay Moreno's Avatar
 
Join Date: 2009
Location: San Antonio, Tx
Posts: 1,270
Thanks: 301
Thanked 449 Times in 309 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

Originally Posted by Terry Jett View Post

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
Hi Terry, our next update to our own WP plugin will work 100% with the Google Mobile Bot, we have held of updating as we are wrapping up our actual WP Mobile Framework and theme.

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!
Jay Moreno is offline  
Unread 22nd Feb 2012, 07:33 PM   #8
Digital Marketer
War Room Member
 
WillR's Avatar
 
Join Date: 2010
Location: Australia
Posts: 12,475
Thanks: 1,984
Thanked 8,187 Times in 4,079 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

Originally Posted by Nail Yener View Post

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.
Nail,

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

Originally Posted by Terry Jett View Post

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,

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.

WillR is offline  
Unread 22nd Feb 2012, 08:55 PM   #9
HyperActive Warrior
War Room Member
 
Nanaswhimsy's Avatar
 
Join Date: 2011
Location: North of Birmingham, AL
Posts: 109
Thanks: 20
Thanked 23 Times in 23 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

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
Nanaswhimsy is offline  
Unread 22nd Feb 2012, 11:36 PM   #10
Digital Marketer
War Room Member
 
WillR's Avatar
 
Join Date: 2010
Location: Australia
Posts: 12,475
Thanks: 1,984
Thanked 8,187 Times in 4,079 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

Originally Posted by Nanaswhimsy View Post

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
Problem with that is you are still serving up the same content to mobile, tablet and PC users which is not always ideal.

WillR is offline  
Unread 23rd Feb 2012, 07:36 AM   #11
Happy in Acuña
War Room Member
 
Terry Jett's Avatar
 
Join Date: 2008
Location: Dallas
Posts: 2,085
Thanks: 263
Thanked 650 Times in 515 Posts
Blog Entries: 2
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

Originally Posted by WillR View Post


Terry,

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.
Thanks Will.

Terry Jett is offline  
Unread 23rd Feb 2012, 03:49 PM   #12
Ultimate Warrior
 
HypeText's Avatar
 
Join Date: 2011
Posts: 734
Thanks: 28
Thanked 181 Times in 131 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

Originally Posted by Jay Moreno View Post

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 yourdomainhere.com - domain hosting 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>
With this code implemented it will redirect visitors with screen sizes smaller than 1024 and also ALL your android visitors.

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
Just some quick Clarification for those not "Coding Adept"

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
HypeText is offline  
Unread 23rd Feb 2012, 04:27 PM   #13
HyperActive Warrior
War Room Member
 
Nanaswhimsy's Avatar
 
Join Date: 2011
Location: North of Birmingham, AL
Posts: 109
Thanks: 20
Thanked 23 Times in 23 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

Originally Posted by WillR View Post

Problem with that is you are still serving up the same content to mobile, tablet and PC users which is not always ideal.
Not if the css is set up to not load certain content based on device.
Nanaswhimsy is offline  
Unread 24th Feb 2012, 12:16 AM   #14
Warrior Member
 
Join Date: 2011
Posts: 12
Thanks: 3
Thanked 8 Times in 5 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

Originally Posted by Nanaswhimsy View Post

Not if the css is set up to not load certain content based on device.
Sorry, but there is currently no CSS-only method to avoid loading content that works across all devices. display:none does not stop the browser from downloading the element in most cases. What about images? Squishing the image to fit does not make it smaller in file size. Some browsers will not download images specified as background images in the css, but some will, and some will not only if the parent element is set to display:none. Having all your images as background images is bad practice, anyway.

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.
M Stacks is offline  
Unread 24th Feb 2012, 05:38 AM   #15
Digital Marketer
War Room Member
 
WillR's Avatar
 
Join Date: 2010
Location: Australia
Posts: 12,475
Thanks: 1,984
Thanked 8,187 Times in 4,079 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

Originally Posted by Nanaswhimsy View Post

Not if the css is set up to not load certain content based on device.
Yes but then the phone is downloading content it doesn't need.

WillR is offline  
Unread 19th Apr 2012, 09:16 AM   #16
Warrior Member
 
Join Date: 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: LOOK CODE INCLUDED! No more Javascript/Android screen size redirection issues...
Share on: 
fb share twitter share gplus share more share

[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
:- )
fabritaly is offline  
Closed Thread


Bookmarks

Tags
android, issues, javascript, mobile, redirect, redirection, screensize


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 08:36 AM.