I am trying to make a javascript alert box that asks the user if he would like to go to the mobile page or not. Right now I have this code :
if (screen.width <= 699) {
alert document.location = "/mobile";
}
else {
alert ("Thanks!");
}
I am trying to make a javascript alert box that asks the user if he would like to go to the mobile page or not. Right now I have this code :
if (screen.width <= 699) {
alert document.location = "/mobile";
}
else {
alert ("Thanks!");
}
Share
Improve this question
edited Mar 18, 2013 at 9:18
gion_13
41.5k10 gold badges98 silver badges111 bronze badges
asked Jan 11, 2012 at 18:04
MIkey27MIkey27
251 silver badge5 bronze badges
1
- This is not a duplicate. It's subtly different than the suggested duplicate article. The duplicate article discusses screen resolution and this question is about detecting mobile devices in general. – Chuck Conway Commented Feb 26, 2013 at 21:20
3 Answers
Reset to default 5I remend using following website's code:
- http://detectmobilebrowsers./
What it does it checking client's userAgent string to find out if it's mobile or not. It can detect most mobile devices also provide more ways to detect including jQuery, JavaScript, PHP, C# and ...
Hope this helps :-)
You could test the navigator.userAgent
property for mobile keywords to determine if the user is navigating your site through a device, and then he would have to confirm
weather to navigate using the mobile or the full version of the site :
var isMobile = /iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent);
if(isMobile && confirm('do you want to see the mobile site?'))
// navigate to the mobile version of the site
location = '/mobile';
Something like
if(navigator.userAgent.match(/Mobile/i)) document.location.href="./mobile"
might work.