admin管理员组文章数量:1332890
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.
本文标签: htmlJavascript mobile detectionStack Overflow
版权声明:本文标题:html - Javascript mobile detection - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742319125a2452422.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论