我的PHP页面上有一个按钮,目前我正在使用此javascript代码打开app store
和play store
,但此代码将直接打开play store
和app store
页面而不是点击按钮,我希望在用户点击按钮后打开它,它将根据浏览器代理打开。谁能帮我?
<script> <script src="http://code.jquery.com/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.com/my/app/flipbizz/idexampleapp';
}
});
</script>
<script src="http://code.jquery.com/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.com/store/apps/details?id=com.exampleapp';
}
});
</script>
<p><button> JOIN ME NOW</button></p>
</div>
</div>
答案 0 :(得分:3)
试试这个
<button onclick="myFunction()">Click me</button>
<script>
function myFunction() {
if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){ window.location.href = 'https://itunes.apple.com/my/app/flipbizz/idexampleapp'; }
if(navigator.userAgent.toLowerCase().indexOf("android") > -1){ window.location.href = 'https://play.google.com/store/apps/details?id=com.exampleapp'; }
//Update #2
if (!navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
window.location.href = 'https://www.google.com'; //Desktop Browser
}
}
</script>