简体   繁体   中英

why isn't window.location.href in Visual composer page builder's Raw js element in Wordpress

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM