0

In my Wordpress website, I have Visual composer page builder plugin. In that, I am creating a button which if click from apple phone, will redirect to Apple store and if clicked from android will redirect to google play store. I am doing this by a script which I put in visual composer's Raw js element. below is the script:

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

<script>
jQuery(function ($) {
    $( document ).ready(function() {
        $(".custom_button").on("click", function(){

        if(navigator.userAgent.toLowerCase().indexOf("android") > -1){ alert('in android');
            window.location.href = 'http://play.google.com/store/apps/details?id=com.truecaller&hl=en';
        }
        if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){ alert('in iphone');
           window.location.href = 'http://itunes.apple.com/';
               alert('after iphone');
         }
        });
     });
  });
</script>

window.location.href is not working. it doesn't redirect. It runs a script and do alert 'in iphone' and 'after iphone' but it is not redirecting to any store.

User27
  • 535
  • 5
  • 25
  • To be clear, your getting your alerts but not the redirect? Or neither the alert or redirect works? – Trevor Dec 19 '17 at 22:06
  • I am getting alert but no redirect – User27 Dec 19 '17 at 22:11
  • Possible duplicate of [Why isnt window.location.href= not forwarding to page using Safari?](https://stackoverflow.com/questions/31223216/why-isnt-window-location-href-not-forwarding-to-page-using-safari) – Nick Fortescue Dec 20 '17 at 17:36

1 Answers1

0

I think this might be a duplicate of (or very similar to) Why isnt window.location.href= not forwarding to page using Safari?

which has some suggested workaround for Safari, which presumably is what you are using on iPhone.

Nick Fortescue
  • 13,530
  • 1
  • 31
  • 37