admin管理员组

文章数量:1355574

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>

本文标签: javascriptRedirect to app store or google store after button clickStack Overflow