JavaScript : Redirect mobile traffic

If you have a basic website, that is designed to work on a desktop platform and you don’t have a mobile theme, there is a little point getting customers to try and use a website not optimize from mobile phone.

This usually occurs when you have a landing page and behind it, do you have some content that is mobile optimized, so for this example, I have a landing page that essentially links to a blog, the landing page is not mobile phone optimized, whereas the blog is mobile phone optimized.

Remember these functions can be deployed and configured with a WAF, if for example, you are using Azure - you can set up a front door as a service or you can use Cloudflare to accomplish this.

In this instance, it makes more sense for mobile phones to skip the landing page and go straight to the blog, this can be accomplished with some JavaScript as shown below….

<script type="text/javascript">
  if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
    location.replace("https://blog.bears.local");
  }
</script>
Previous Post Next Post

نموذج الاتصال