alexw
New Coder
Hello everyone,
I am using the script below to direct users to Instagram via the app or the website based on the device they are on. The script works great until it is used on a phone that does not have the Instagram app. The user without the app will get an invalid address error message. Is there a way to update the script to redirect mobile users without the app to the Instagram website link instead of the app link?
I am using the script below to direct users to Instagram via the app or the website based on the device they are on. The script works great until it is used on a phone that does not have the Instagram app. The user without the app will get an invalid address error message. Is there a way to update the script to redirect mobile users without the app to the Instagram website link instead of the app link?
JavaScript:
<script>
function isMobile() {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
// true for mobile device
window.open("instagram://user?username=username");
} else {
// false for non-mobile device
window.open("https://www.instagram.com/username", "_blank");
}
}
</script>
Last edited: