我的 PHP 页面上有一个按钮,目前我正在使用此 javascript 代码打开 and app store,play store但此代码将直接打开play storeandapp 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>
Run Code Online (Sandbox Code Playgroud)
尝试这个
<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>
Run Code Online (Sandbox Code Playgroud)