es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Redirigir desde el navegador de Facebook a Safari Apple

Este script redirige a los usuarios del navegador de Facebook al navegador de Google Chrome en dispositivos Android, necesito que haga lo mismo en:

  • Navegador de Instagram en Android (Google Chrome) y iPhone (Safari)
  • Navegador de Facebook en iPhone (redirigir a Safari)

Aquí está el código actualmente en funcionamiento:

<script>
    function isFacebookApp() {
        var ua = navigator.userAgent || navigator.vendor || window.opera;
        return (ua.indexOf("FBAV") > -1) || (ua.indexOf("FBAN") > -1);
    }
if (isFacebookApp()) {
    var currentLink = location.href;
    if (currentLink.indexOf('https') > -1) {
        var currentLink = currentLink.replace('https://', '');
        currentLink = currentLink.replace('www.', '');
        var chromeLink = "intent://" + currentLink + "#Intent;scheme=https;package=com.android.chrome;end";
        window.location.href = chromeLink;
    }
    if (currentLink.indexOf('http') > -1) {
        var currentLink = currentLink.replace('http://', '');
        currentLink = currentLink.replace('www.', '');
        var chromeLink = "intent://" + currentLink + "#Intent;scheme=http;package=com.android.chrome;end";
        window.location.href = chromeLink;
    }
} 
</script>

Gracias.

Tags:  , ,

Answer

  1. Avatar for davy.ai

    Para redirigir el navegador de Instagram en Android a Google Chrome y el navegador de Instagram en iPhone a Safari, puede modificar el código existente de la siguiente manera:

    <script>
      function isFacebookApp() {
        var ua = navigator.userAgent || navigator.vendor || window.opera;
        return (ua.indexOf("FBAV") > -1) || (ua.indexOf("FBAN") > -1);
      }
    
      function isInstagramApp() {
        var ua = navigator.userAgent || navigator.vendor || window.opera;
        return (ua.indexOf("Instagram") > -1);
      }
    
      if (isFacebookApp()) {
        var currentLink = location.href;
    
        if (currentLink.indexOf('https') > -1) {
          var currentLink = currentLink.replace('https://', '');
          currentLink = currentLink.replace('www.', '');
    
          var chromeLink = "intent://" + currentLink + "#Intent;scheme=https;package=com.android.chrome;end;";
          window.location.href = chromeLink;
        }
        if (currentLink.indexOf('http') > -1) {
          var currentLink = currentLink.replace('http://', '');
          currentLink = currentLink.replace('www.', '');
    
          var chromeLink = "intent://" + currentLink + "#Intent;scheme=http;package=com.android.chrome;end;";
          window.location.href = chromeLink;
        }
    
      } else if (isInstagramApp()) {
        var currentLink = location.href;
    
        if (currentLink.indexOf('instagram.com') > -1) {
          if (navigator.userAgent.match(/iPad|iPhone|iPod/i)) {
            window.location.href = "https://" + currentLink;
          } else if (navigator.userAgent.match(/Android/i)) {
            var chromeLink = "intent://" + currentLink + "#Intent;scheme=https;package=com.android.chrome;end;";
            window.location.href = chromeLink;
          }
        }
      }
    </script>
    

    Para redirigir el navegador de Facebook en iPhone a Safari, puede modificar el código de la siguiente manera:

    <script>
      function isFacebookApp() {
        var ua = navigator.userAgent || navigator.vendor || window.opera;
        return (ua.indexOf("FBAV") > -1) || (ua.indexOf("FBAN") > -1);
      }
    
      function isInstagramApp() {
        var ua = navigator.userAgent || navigator.vendor || window.opera;
        return (ua.indexOf("Instagram") > -1);
      }
    
      if (isFacebookApp()) {
        var currentLink = location.href;
    
        if (currentLink.indexOf('https') > -1) {
          var currentLink = currentLink.replace('https://', '');
          currentLink = currentLink.replace('www.', '');
    
          var chromeLink = "intent://" + currentLink + "#Intent;scheme=https;package=com.android.chrome;end;";
          window.location.href = chromeLink;
        }
        if (currentLink.indexOf('http') > -1) {
          var currentLink = currentLink.replace('http://', '');
          currentLink = currentLink.replace('www.', '');
    
          var chromeLink = "intent://" + currentLink + "#Intent;scheme=http;package=com.android.chrome;end;";
          window.location.href = chromeLink;
        }
    
      } else if (isInstagramApp()) {
        var currentLink = location.href;
    
        if (currentLink.indexOf('instagram.com') > -1) {
          if (navigator.userAgent.match(/iPad|iPhone|iPod/i)) {
            window.location.href = "https://" + currentLink;
          } else if (navigator.userAgent.match(/Android/i)) {
            var chromeLink = "intent://" + currentLink + "#Intent;scheme=https;package=com.android.chrome;end;";
            window.location.href = chromeLink;
          }
        }
      } else if (navigator.userAgent.match(/iPad|iPhone|iPod/i) && (navigator.userAgent.indexOf("FBAN") > -1 || navigator.userAgent.indexOf("FBAV") > -1)) {
        window.location.href = "https://" + window.location.hostname + window.location.pathname;
      }
    </script>
    

    Tenga en cuenta que el código modificado incluye una función adicional isInstagramApp() para detectar el navegador de Instagram y bloques de código para cada navegador basados en el user-agent detectado.

Comments are closed.