ventana sociales redes pagina otra inventor enlazar como app aplicacion agregar abrir javascript mobile-browser

javascript - sociales - Cómo iniciar aplicaciones(facebook/twitter/etc) desde el navegador móvil pero retroceda al hipervínculo si la aplicación no está instalada



como enlazar en app inventor (1)

Espero que haya alguna forma de detectar si un esquema uri :, está registrado o no en un dispositivo móvil desde el navegador.

IE: Me gustaría comprobar si las aplicaciones de facebook, twitter, pinterest están instaladas y se pueden iniciar desde su esquema uri asociado.

if(fb_isInstalled) { // href="fb://profile/...." } else { // href="http://m.facebook.com/..." }

Básicamente, si el usuario ha instalado Facebook, inicie la aplicación, pero vuelva a la versión móvil del sitio web de fb si la aplicación no está instalada.


Creo que tengo una solución de trabajo.

<!-- links will work as expected where javascript is disabled--> <a class="intent" href="http://facebook.com/someProfile" data-scheme="fb://profile/10000">facebook</a>

Y mi javascript funciona así.
nota: hay un poco de jQuery mezclado allí, pero no necesitas usarlo si no quieres.

(function () { // tries to execute the uri:scheme function goToUri(uri, href) { var start, end, elapsed; // start a timer start = new Date().getTime(); // attempt to redirect to the uri:scheme // the lovely thing about javascript is that it''s single threadded. // if this WORKS, it''ll stutter for a split second, causing the timer to be off document.location = uri; // end timer end = new Date().getTime(); elapsed = (end - start); // if there''s no elapsed time, then the scheme didn''t fire, and we head to the url. if (elapsed < 1) { document.location = href; } } $(''a.intent'').on(''click'', function (event) { goToUri($(this).data(''scheme''), $(this).attr(''href'')); event.preventDefault(); }); })();

También presenté esto como una gist que puedes desentrañar. También puede incluir la gist en un jsfiddle si lo desea.

Editar

@kmallea bifurcó la esencia y la simplificó radicalmente. https://gist.github.com/kmallea/6784568

// tries to execute the uri:scheme function uriSchemeWithHyperlinkFallback(uri, href) { if(!window.open(uri)){ window.location = href; } }

// `intent` is the class we''re using to wire this up. Use whatever you like. $(''a.intent'').on(''click'', function (event) { uriSchemeWithHyperlinkFallback($(this).data(''scheme''), $(this).attr(''href'')); // we don''t want the default browser behavior kicking in and screwing everything up. event.preventDefault(); });