Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open link in external browser instead of in-app (instagram)?

Tags:

instagram

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

like image 671
Mahdi Saheban Avatar asked May 07 '18 11:05

Mahdi Saheban


People also ask

How do I open a link without opening an app?

window. open('https://www.google.com', '_system'); This opens the URL in the device's browser.


5 Answers

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

like image 57
Jorrit Schippers Avatar answered Oct 22 '22 17:10

Jorrit Schippers


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

like image 36
iKBAHT Avatar answered Oct 22 '22 18:10

iKBAHT


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

like image 22
Vincenzo Avatar answered Oct 22 '22 18:10

Vincenzo


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;
            }
        }
    }
}
like image 1
Mansour Alnasser Avatar answered Oct 22 '22 16:10

Mansour Alnasser


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>
like image 1
MrXo Avatar answered Oct 22 '22 18:10

MrXo