[Javascript] Redirect mobile users to another page

Post a reply

:
In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review
   

Expand view Topic review: [Javascript] Redirect mobile users to another page

Re: [Javascript] Redirect mobile users to another page

Post by admin » Thu Apr 18, 2019 12:05 pm

Basic Code. Redirects all smart phones with screens smaller than 700 pixels wide to another page.

Code: Select all
<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "/home/index.php";
}
//-->
</script>

[Javascript] Redirect mobile users to another site

Post by admin » Mon Nov 06, 2017 11:19 am

Using the same instructions as above except you replace "http://my-site.com" with your domain name.

Code: Select all
<script type="text/javascript"> 
    var mobile = (/iphone|ipod|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())); 
    if (mobile) {
window.location ="http://my-site.com/mobile.html";
    }
</script>

<script type="text/javascript">
   var isAndroid = (/android/i.test(navigator.userAgent.toLowerCase()));
   if (isAndroid) {
   // alert("Android");
      if (screen.width < 800) {
         // alert("android portrait");
   window.location ="http://my-site.com/mobile.html";   
      } else if (screen.height < 800) {
window.location ="http://my-site.com/mobile.html";   
         //alert("android landscape");
      }
   }
</script>

[Javascript] Redirect mobile users to another page

Post by admin » Fri Mar 31, 2017 3:20 pm

Create an html landing page (e.g. mobile.htm) or redirect your visitors to another site.
Place code below before the <head>.
Just replace your-site.com with your domain name.

Code: Select all
<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "http://www.your-site.com/mobile.htm";
}
//-->
</script>
<script type="text/javascript">
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
   location.replace("http://www.your-site.com/mobile.htm");
}
-->
</script>

Top

cron