最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Redirect to app store or google store after button click - Stack Overflow

programmeradmin0浏览0评论

I have a button on my PHP page, currently I'm using this javascript code to open the app store and play store, but this code will directly open the play store and app store page and not on the button click, I want it to open after the user click on the button and it will open based on the browser agent. Can anyone help me?

 <script> <script src=".min.js" type="text/javascript"></script>

<script>
    $(document).ready(function (){
     if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){
         window.location.href = '';
     }
    });
</script>

<script src=".min.js" type="text/javascript"></script>

<script>
    $(document).ready(function (){
     if(navigator.userAgent.toLowerCase().indexOf("android") > -1){
         window.location.href = '.exampleapp';
     }
    });
</script>

  <p><button> JOIN ME NOW</button></p>
</div> 

</div>

I have a button on my PHP page, currently I'm using this javascript code to open the app store and play store, but this code will directly open the play store and app store page and not on the button click, I want it to open after the user click on the button and it will open based on the browser agent. Can anyone help me?

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

<script>
    $(document).ready(function (){
     if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){
         window.location.href = 'https://itunes.apple./my/app/flipbizz/idexampleapp';
     }
    });
</script>

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

<script>
    $(document).ready(function (){
     if(navigator.userAgent.toLowerCase().indexOf("android") > -1){
         window.location.href = 'https://play.google./store/apps/details?id=.exampleapp';
     }
    });
</script>

  <p><button> JOIN ME NOW</button></p>
</div> 

</div>
Share Improve this question edited Mar 6, 2018 at 6:54 Gufran Hasan 9,4117 gold badges43 silver badges55 bronze badges asked Mar 6, 2018 at 4:05 zatuzatu 531 silver badge4 bronze badges 3
  • 2 Add an onclick to the button. – Agney Commented Mar 6, 2018 at 4:07
  • The use of jQuery here is very inteligent. You code 20 lines when only two were needed. Cool. – Silvio Tamaso D'Onofrio Commented Mar 6, 2018 at 4:20
  • can you be more specific which part should i add it? iam a newbie here – zatu Commented Mar 6, 2018 at 4:21
Add a ment  | 

1 Answer 1

Reset to default 6

Try this

<button onclick="myFunction()">Click me</button>


<script>
function myFunction() {
    if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){ window.location.href = 'https://itunes.apple./my/app/flipbizz/idexampleapp'; }

    if(navigator.userAgent.toLowerCase().indexOf("android") > -1){ window.location.href = 'https://play.google./store/apps/details?id=.exampleapp'; }

    //Update #2
    if (!navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
         window.location.href = 'https://www.google.'; //Desktop Browser
    }
}
</script>
发布评论

评论列表(0)

  1. 暂无评论