I've been trying to figure out how to open an URL that you open within the Instagram app, in an external browser (Safari, Chrome) rather than the in-build Instagram-browser.
i want that link in website part of instagram asks to leave Instagram app and opens external browser visiting website.
I tried a lot of things, like using window.open with _blank, _system, etc. Also tried these within a
window. open('https://www.google.com', '_system'); This opens the URL in the device's browser.
This is not possible, as it is a deliberate choice of the Instagram developers to use their own browser control.
You can detect Instagram in-app browser
navigator.userAgent.includes("Instagram")
and put link like that
<a href={location.href} target='_blank' download>Open in browser</a>
All magic in 'download' key word. When user clicks the link it will be redirected to the native browser. It work perfect in android. I haven't tested it on iOS
I found an interesting article that talks about it, try to work around with this bit of code to make the Instagram’s in-app browser redirect to your website
<script>
if(navigator.userAgent.includes("Instagram")){
window.location.href = "https://mywebsite.com/DummyBytes";
}
</script>
For more information have a look at the article: https://medium.com/@sasan.salem/opening-of-your-website-in-the-viewers-external-browser-automatically-instead-of-instagram-s-8aca5ee7e22f
You can solve it by acting as a file to be downloaded, then the in-app browser will redirect you to the mobile browser.
not working on iPhone. :(
<?php
$userAgent = $_SERVER['HTTP_USER_AGENT'];
if (strpos($userAgent, 'Instagram')) {
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename= blablabla');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
@readfile($file);
die();
}
?>
namespace DotNet.Controller
{
public class DummyBytesController : ApiController
{
[HttpGet]
public HttpResponseMessage Get()
{
HttpResponseMessage Response;
string UserAgent = HttpContext.Current.Request.UserAgent;
if(UserAgent.Contains("Instagram"))
{
Response = new HttpResponseMessage(HttpStatusCode.OK);
Response.Content = new ByteArrayContent(new byte[50]);
Response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return Response;
}
else
{
Response = Request.CreateResponse(HttpStatusCode.Redirect);
Response.Headers.Location = new Uri("https://mywebsite.com");
return Response;
}
}
}
}
You can add this script to head to redirect to chrome:
<script>
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
var str = navigator.userAgent;
var instagram = str.indexOf("Instagram");
var facebook = str.indexOf("FB");
if (/android/i.test(userAgent) && (instagram != -1 || facebook != -1) ) {
document.write("<a target=\"_blank\" href=\"https://yourdomain.com\" download id=\"open-browser-url\">Please wait. Proceed to Chrome</a>");
window.stop();
let input = document.getElementById('open-browser-url');
if (input) {
input.click();
}
}
</script>
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