i have this link on my html page that open Instagram app on specific user:
<a href="instagram://user?username={USERNAME}">Link to Instagram Profile</a>
I was looking for the ways to run the url 'instagram://user?username={USERNAME}' automatically (like automatic redirect).
Here is what i've tried in the head:
1.
<meta http-equiv="refresh" content="0; url=instagram://user?username={USERNAME}" />
2.
<script type="text/javascript">
window.location.href = "instagram://user?username={USERNAME}"
</script>
3. variation suggested by @Nitin-bagoriya
<script> function load() { window.location.href = "instagram://user?username={USERNAME}"}; window.onload = load; </script>
variation suggested by @Giuseppe
addEventListener('load', load);
But when i browse there - nothing happen. It was tested on android with instagram app installed.
I wonder is there any way to run Instagram app automatically via redirect so user dont need to click the link?
Recaping, so others can benefit.
Javascript solutions based in "window.location.href" are not supported in mobile OS (iOS or Android).
What seemed to first work is adding the redirect in PHP, as answered here, like this:
<?php header("Location: instagram://user?username={USERNAME}") ; ?>
iOS provides "window.location.replace" to do a redirect, while what Android provides is "document.location". Thus, you need to device-detect first, and then apply the proper redirect.
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 );
}
See here for details: iOS and Android redirects in javascript
You Just need to add window.onLoad in head section of .html file
Your Final code will be like:
window.onLoad = window.location.href = "instagram://user?username={USERNAME}"
OR you can create a function which contain your window.location.href = "instagram://user?username={USERNAME}" and execute it on window.onload !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With