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
1 Answer
Reset to default 6Try 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
版权声明:本文标题:javascript - Redirect to app store or google store after button click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744042223a2580871.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论