I want to redirect an URL with PHP or JavaScript. If the app is installed, It will be opened in-app (like in Instagram, YouTube app). If not, it will be opened in the browser. https://app.urlgeni.us/ can do this and I want to create a system like that. How can I do that too?
My codes are like that but they don't work.
PHP:
<?php header("Location: instagram://user?username={USERNAME}"); ?>
JavaScript:
var destination = "instagram://user?username={USERNAME}";
if( navigator.userAgent.match(/Android/i) ) {
// use Android's redirect
document.location = destination;
}
else {
// use iOS redirect
window.location.replace( destination );
}
setTimeout(function(){
window.location.replace("https://www.instagram.com/{USERNAME}/");
}, 1000);
Source: How to make redirect to instagram://user?username={username}
Additional: When I create a link like this and click it manually, it works. But when I redirect to this link, it doesn't work.
<a href="instagram://user?username={USERNAME}">Open in Instagram app</a>
This doesn't work either:
<a id="link" href="instagram://user?username={USERNAME}">Open in Instagram app</a>
<script type="text/javascript">
var link = document.getElementById("link");
link.click();
</script>