You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

应用内浏览器跳转外部Chrome时URL冒号丢失的问题求助

应用内浏览器跳转外部Chrome时URL冒号丢失的问题求助

我翻了好多个Stack Overflow的问题都没找到合适的解决方案,于是结合ChatGPT的一些思路写了个脚本——现在能成功把应用内浏览器(比如Instagram、Facebook这类)里的链接转到Chrome打开,但遇到个头疼的问题:跳转后的URL里的冒号:不见了,本来应该是https://www.example.com,结果变成了https//www.example.com。

下面是我写的脚本:

(function () {
    const userAgent = navigator.userAgent || navigator.vendor || window.opera;

    // Detect if the current browser is an in-app browser (Instagram, Facebook, etc.)
    const isInAppBrowser = /FBAN|FBAV|Instagram|Line|Twitter|WhatsApp|Snapchat/i.test(userAgent);

    // Detect iOS
    const isIOS = /iPhone|iPad|iPod/i.test(userAgent);

    if (isInAppBrowser) {
      const url = "https://www.example.com/"; // Replace with your website's URL

      // Prevent infinite redirect loop using sessionStorage
      const alreadyRedirected = sessionStorage.getItem("redirected");
      if (!alreadyRedirected) {
        sessionStorage.setItem("redirected", "true");

        if (isIOS) {
          // Try to open in Chrome using the googlechrome:// scheme
          const chromeURL = `googlechrome://${url}`;

          setTimeout(() => {
            window.location.href = chromeURL;

            // Fallback to Safari after 500ms if Chrome isn't installed or doesn't open
            setTimeout(() => {
              window.location.href = url; // Fallback to Safari
            }, 500);
          }, 500);
        } else {
          // Android behavior: Trigger intent for Chrome or default browser
          window.location.href = `intent://${url.replace('https://', '')}#Intent;scheme=https;package=com.android.chrome;end;`;

          // Fallback if intent fails
          setTimeout(() => {
            window.location.href = url;
          }, 500);
        }
      }
    }
  })();

现在的问题就是,跳转后Chrome打开的是https//www.example.com,冒号直接没了,有没有大佬能帮忙分析下问题出在哪,怎么修复这个问题呀?

备注:内容来源于stack exchange,提问作者urfusion

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 17:59:35