34

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

Mahdi Saheban
  • 341
  • 1
  • 3
  • 3

7 Answers7

10

This is not possible, as it is a deliberate choice of the Instagram developers to use their own browser control.

Jorrit Schippers
  • 1,538
  • 12
  • 17
  • But there is an option. When using on the desktop web version, you have the possibility to open the links in new tabs of your web browsers. – Ebrahim Oct 11 '18 at 16:53
  • @Ebrahim this question specifically mentions "from the Instagram app" which implies the user is interested in native application rather than the website, and therefore their answer is correct. – technoplato Dec 10 '21 at 14:36
  • @Ebrahim Instagram in app browser is not one of the "tabs". It's a complete browser. On desktop, you can't programmatically open links into a different browser from the current one (say Firefox from Chrome). – Qumber Aug 16 '23 at 05:54
9

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

iKBAHT
  • 644
  • 6
  • 17
  • 2
    From https://medium.com/@romaia/i-came-up-with-a-similar-solution-that-is-to-use-the-download-attribute-of-the-a-tag-13f642005a94 – iKBAHT Sep 07 '21 at 11:53
  • 2
    it doesn't take the user from in-app browser to his default browser on his phone tbh – Saeed May 16 '22 at 08:24
  • doesn't work in IOS – Madian Malfi Jul 13 '22 at 21:07
  • I did some testing on iOS and found that the iOS WebView has a built-in file renderer. For this reason on iOS the external browser does not open. Maybe sending some specific file type or some specific mime-type that is not supported by the file renderer will open the external browser. – Eduardo Mior Oct 20 '22 at 13:51
  • Not working in android & ios – Rajesh Jan 01 '23 at 06:58
4

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

Vincenzo
  • 375
  • 3
  • 15
  • Will this work for iOS? The article you have mentioned tells that this is for Android – Eugene Mala Jul 09 '21 at 21:16
  • I wouldn't know how to help you at the moment, it is in general hard to make it work even on android devices. You need to be able to open up a browser instance and send Instagram in the background. – Vincenzo Jul 12 '21 at 16:13
  • I did some testing on iOS and found that the iOS WebView has a built-in file renderer. For this reason on iOS the external browser does not open. Maybe sending some specific file type or some specific mime-type that is not supported by the file renderer will open the external browser. – Eduardo Mior Oct 20 '22 at 13:50
3

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>
MrXo
  • 131
  • 1
  • 9
1

Opening of your website in the viewer’s external browser automatically instead of Instagram’s in-app browser (on Android devices).

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



<?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();
    }
?>

ASP.NET Web API:

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;
            }
        }
    }
}
Mansour Alnasser
  • 4,446
  • 5
  • 40
  • 51
0

It can be written more elegantly but the solution as of 21.04.2023 is:

var ua = navigator.userAgent || navigator.vendor;
  var isInstagram = (ua.indexOf('Instagram') > -1) ? true : false;
  var str = navigator.userAgent;
  var i = str.indexOf("Instagram");
  if (isInstagram) {
    if (/iPad|iPhone|iPod/.test(ua)) {
      window.location.href = 'googlechrome://example.com';
      return;
    }
    window.location.href = 'intent:https://example.com#Intent;end';
    return;
  }

The only drawback is that on IOS, Safari which is the default browser does not have a URL Scheme that you can use, thus you have to resort to using chrome. It will fail if the user does not have Chrome installed.

-16

Actually, there is a possibility. You first access the link with the in-app browser, then you click on the 3-dots button on the right top of the page and select "open in Chrome".

Charles
  • 1
  • 1