Skip to content

Instantly share code, notes, and snippets.

@goellner
Created August 17, 2022 12:38
Show Gist options
  • Save goellner/a34c78fa9a27be1a7cbad8572c7a574c to your computer and use it in GitHub Desktop.
Save goellner/a34c78fa9a27be1a7cbad8572c7a574c to your computer and use it in GitHub Desktop.
Trick instagram in-app browser to open in system browser
<script type="text/javascript">
// detect instagram in-app browser on android and force a redirect
if(navigator.userAgent.includes("Instagram") && navigator.userAgent.includes("Android")){
var socialsRedirectURL = encodeURIComponent(window.location.href);
window.location.href = "https://yourdomain.example/socialredirect.php?redirect=" + socialsRedirectURL;
}
</script>
<?php
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$redirectURL = $_GET['redirect'];
if (strpos($userAgent, 'Instagram') && strpos($userAgent, 'Android')) {
// trick the android instagram in-app by trying to download a file.
// This will open the link in the system browser instead.
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename=dummy');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
}
else {
header('Location: ' . $redirectURL);
}
?>
@hrishi85
Copy link

I've tested it and it does not work for iOS

@amitbk
Copy link

amitbk commented Oct 28, 2024

Not working for android also, any other solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment