[英]Detect and redirect to mobile site
A website I'm making has a separate set of files for mobile view due to the html layout being difficult to make responsive. 由于html布局难以响应,因此我正在制作的网站具有用于移动视图的单独文件集。
I'm looking for code that will detect if the user is on a mobile, then redirect them to the m.website.com domain instead. 我正在寻找可检测用户是否在移动设备上的代码,然后将其重定向到m.website.com域。
I found this: 我找到了这个:
<script type="text/javascript">
if (screen.width <= 699) {
document.location = "YOUR-MOBILE-SITE.com";
}
</script>
But on most mobile devices, there is an option to view the desktop version of websites, but it looks like this javascript will ignore that and keep redirecting anyway. 但是在大多数移动设备上,都有一个选项可以查看网站的桌面版本,但是此javascript似乎会忽略它并继续重定向。
Is there a better way of doing this? 有更好的方法吗?
This is one of the best module available online,i used the same for my website,it is supported by a major number of mobile devices,many developers has contributed to this repository,might be helpful to you,also it caters for redirection to website through mobile version 这是在线上可用的最佳模块之一,我在我的网站上也使用了相同的模块,它得到了大量移动设备的支持,许多开发人员都对该存储库做出了贡献,可能会对您有所帮助,还可以重定向到网站通过手机版
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.