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!
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:
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With