检测移动用户 [英] Detection of mobile users
本文介绍了检测移动用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function isMobile() {
var index = navigator.appVersion.indexOf("Mobile");
return (index > -1);
}
function setStyleMobile() {
document.write("<style>body { font-size: 3em; } </style>");
}
function makeFontTripleSize() {
document.write("<style>body { font-size: 5em; } </style>");
}
if (isMobile()) {
setStyleMobile();
document.write("Mobile browser");
}
else {
makeFontTripleSize();
document.write("Regular browser");
}
我有区分移动用户和普通桌面用户的代码,但是我不想增加字体大小,我想将他们重定向到两个不同的URL.您有什么建议吗?任何帮助将不胜感激.
Hi,
I have the code to differentiate the mobile users and normal desktop users but i don`t want to increase the font size i want to redirect them to two different URL`s Can you have any suggestions. Any help would be appreciated.
推荐答案
尝试使用window.location
进行重定向.
Try usingwindow.location
for redirect.
window.location.assign('http://www.abc.com')
或
or
window.location = 'http://www.abc.com'
^ ].
Google[^] for more.
这篇关于检测移动用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文