简体   繁体   English

如何从 Instagram 应用内浏览器页面链接打开默认浏览器?

[英]How open default browser from instagram in-app browser page link?

Some pages in my site have a PWA install feature (that are not supported by instagram in-app browser).我网站中的某些页面具有 PWA 安装功能(instagram 应用内浏览器不支持)。 So when my visitor click in theses pages links I wanna open it in native browser, instead keeping navigation within Instagram in-app browser.因此,当我的访问者单击这些页面链接时,我想在本机浏览器中打开它,而不是在 Instagram 应用程序内浏览器中保持导航。

I tried the following:我尝试了以下方法:

$('.my-link').on('click', function(evt){
    if(navigator.userAgent.includes("Instagram")){
      evt.preventDefault();
      window.open($(this).attr('href'), '_blank');
      return false;
    }

    return true;
});  

The if condition matchs true, but the target pages remains opening in Instagram in-app browser. if 条件匹配 true,但目标页面仍然在 Instagram 应用程序内浏览器中打开。 I have tried window.open($(this).attr('href'), '_system');我试过window.open($(this).attr('href'), '_system'); also, with no success.也,没有成功。

Any clue?有什么线索吗?

Update 1更新 1

Tried to use URIs schemes to force browser opening, but unfortunately it doest seem to be a good solution.尝试使用 URIs 方案强制打开浏览器,但不幸的是它似乎不是一个好的解决方案。 Safari doesnt have an URI scheme. Safari 没有 URI 方案。 Google Chrome does, but we cant garantee user has Chrome Browser in Android and we cant detect what browser user has.谷歌浏览器可以,但我们不能保证用户在 Android 中拥有 Chrome 浏览器,我们无法检测用户拥有什么浏览器。

$('a.new-window-if-instagram').on('click', function(evt){
    if(navigator.userAgent.includes("Instagram")){
      
      if (/android/i.test(navigator.userAgent)) {
        evt.preventDefault();

        var url = $(this).attr('href').replace("https://", "googlechromes://");
        url = url.replace("http://", "googlechrome://");
        window.open(url, '_blank');

        return false;
      }

      if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
        // Safari doest have URI scheme...
      }
    }

    return true;
}); 

I'm currently having the same issue, but at least I found a working solution for Android.我目前遇到了同样的问题,但至少我找到了适用于 Android 的有效解决方案。 I don't know if you are using PHP as your back-end language, but if other people find this, this might be useful:我不知道您是否使用 PHP 作为后端语言,但如果其他人发现了这一点,这可能很有用:

<?php

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if ((strpos($ua, 'mobile/') !== false) && (strpos($ua, 'safari/') == false)) // Validation code for iOS mobile
{
    // Show a message that ask user to open with default browser
}
else if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) // Validation code for Android mobile
{
    header('Content-type: application/pdf');
    header('Content-Transfer-Encoding: binary');
    header('Accept-Ranges: bytes');
}

This is a validation for iOS in-app browsers and Android in-app browsers.这是对 iOS 应用内浏览器和 Android 应用内浏览器的验证。

For Android : We change the content type of the page to PDF.对于 Android :我们将页面的内容类型更改为 PDF。 Since the in-app browser can't handle PDF files, it will open the page in a real browser (the default one defined in the user's settings).由于应用内浏览器无法处理 PDF 文件,它将在真实浏览器(用户设置中定义的默认浏览器)中打开页面。 When the page will load again, the validation will fail since it's not an in-app browser again.当页面再次加载时,验证将失败,因为它不再是应用内浏览器。

For iOS : Since we can validate the in-app browser in iOS but can't redirect the user automaticly, what I'm doing for the moment is showing a message that ask the user to open this page with his default browser (you can change the message with a switch case on the User-Agent since it's not the same step for every in-app browser)对于 iOS :由于我们可以在 iOS 中验证应用内浏览器,但不能自动重定向用户,我目前正在做的是显示一条消息,要求用户使用他的默认浏览器打开此页面(您可以User-Agent上的 switch case 更改消息,因为每个应用内浏览器的步骤都不相同)

If I ever find a working solution for iOS, I will update my answer.如果我找到适用于 iOS 的可行解决方案,我会更新我的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在外部浏览器而不是应用内(instagram、iPhone)中打开链接? - How to open link in external browser instead of in-app (instagram, IPhone)? Instagram 链接打开应用内浏览器而不是外部/本机浏览器 - Instagram links open in-app browser instead of external/native browser 如何在外部浏览器而不是应用内打开链接? - How to open link in external browser instead of in-app? 如何强制 Instagram 在 Safari 中而不是在应用程序浏览器中打开链接 - How to force Instagram to open a link in Safari rather than the in app browser iOS-如何在默认浏览器(Safari或Chrome)而非应用内浏览器中打开链接? - iOS - How to open the links in the default browser (Safari or Chrome) instead of the in-app browser? 在Instagram应用内浏览器裁剪方面有什么解决方法? - Any workaround on Instagram in-app browser cropping? 限制用户在应用内浏览器中打开电子邮件链接 - Restrict user to open email link in-app browser 有没有办法强制从Facebook的应用内浏览器中打开Chrome链接? - Is there any way to force a link to open in Chrome from Facebook's in-app browser? 浏览器窗口中的应用内FB页面插件链接 - In-app FB Page plugin link in browser window 如何在HTA的默认Web浏览器中打开链接? - How can I open a link in the default web browser from an HTA?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM