A website I'm making has a separate set of files for mobile view due to the html layout being difficult to make responsive.
I'm looking for code that will detect if the user is on a mobile, then redirect them to the m.website domain instead.
I found this:
<script type="text/javascript">
if (screen.width <= 699) {
document.location = "YOUR-MOBILE-SITE";
}
</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.
Is there a better way of doing this?
A website I'm making has a separate set of files for mobile view due to the html layout being difficult to make responsive.
I'm looking for code that will detect if the user is on a mobile, then redirect them to the m.website. domain instead.
I found this:
<script type="text/javascript">
if (screen.width <= 699) {
document.location = "YOUR-MOBILE-SITE.";
}
</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.
Is there a better way of doing this?
Share Improve this question asked Jan 9, 2015 at 10:07 HippoDuckHippoDuck 2,2044 gold badges31 silver badges51 bronze badges 2- possible duplicate of Mobile page redirect issue – Hacketo Commented Jan 9, 2015 at 10:11
- @Hacketo Thanks, I did search but didn't find that post. - Edit: No that's a different issue in the post. Although the answer is useful. – HippoDuck Commented Jan 9, 2015 at 10:19
1 Answer
Reset to default 4This 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
Redirection to Mobile Site