Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  12] [ 4]  / answers: 1 / hits: 29692  / 13 Years ago, tue, august 9, 2011, 12:00:00

I advertise a company, basicaly I'm an affiliate. I want to redirect my mobile viewers to the mobile version of my affiliate website. I'm thinking of doing this with screen resolution. Basicaly, if the screen resolution is unde 800 x 600, chances are big the guest is using a mobile phone.



Is this a good ideea?



Here is the code:



if ( (screen.width < 800) && (screen.height < 600) ) { 
window.location = 'mobilesite';
}


Ty!


More From » jquery

 Answers
14

It's generally much safer to check the browser's user-agent, as then you will know whether they are on an Android, iPhone, iPad, iPod, Nokia, ..., and you are given greater flexibility to direct the user from there. I use the following Javascript (probably borrowed from another source):



 var isMobile = function() {
console.log(Navigator: + navigator.userAgent);
return /(iphone|ipod|ipad|android|blackberry|windows ce|palm|symbian)/i.test(navigator.userAgent);
};


Screen width is an available technique. I usually see this used with CSS Media Queries, changing the content based on device-width and device-height. E.g.



 @media only screen and (max-device-width: 480px) {
/* For small devices, just CSS */
}


To go with the technique of screen width / height, this is from Mozilla docs:



 // crude way to check that the screen is at 1024x768
if (window.screen.width < 1000) {
// resolution is below 10 x 7
window.location = 'm.mysite.com'; //for example
}


Here is an in-depth list of mobile screen resolutions.



A few caveats:




  1. If a user goes to www.yoursite.com/events/15, you are going to forward the user directly back to m.yoursite.com. This can be very frustrating when trying to visit a link on a mobile device. You should try to reconstruct the proper URL either by a Javascript library (see Crossroads.js) or on the server using a redirect.

  2. As mobile devices get better at rendering and interaction, be aware that oftentimes users may prefer to see the original site instead of the mobile site, full stop. Try to provide a method back to the main site.



    Hope this all helps you suss out your solution!



[#90731] Sunday, August 7, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jonrened

Total Points: 627
Total Questions: 114
Total Answers: 99

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
jonrened questions
Mon, Nov 2, 20, 00:00, 4 Years ago
Tue, May 19, 20, 00:00, 4 Years ago
Tue, Jan 21, 20, 00:00, 4 Years ago
Thu, Nov 7, 19, 00:00, 5 Years ago
;