Pregunta

¿Alguien tiene un ejemplo de script que pueda funcionar de manera confiable en IE / Firefox para detectar si el navegador es capaz de mostrar contenido flash incrustado? Digo confiablemente porque sé que no es posible el 100% del tiempo.

¿Fue útil?

Solución

SWFObject es muy confiable. Lo he usado sin problemas durante bastante tiempo.

Otros consejos

Estoy de acuerdo con Max Stewart . SWFObject es el camino a seguir. Me gustaría complementar su respuesta con un ejemplo de código. Esto debería ayudarte a comenzar:

Asegúrese de haber incluido el archivo swfobject.js (consígalo aquí ):

<script type="text/javascript" src="swfobject.js"></script>

Entonces utilízalo así:

if(swfobject.hasFlashPlayerVersion("9.0.115"))
{
    alert("You have the minimum required flash version (or newer)");
}
else
{
    alert("You do not have the minimum required flash version");
}

Reemplazar " 9.0.115 " Con cualquier versión de flash mínima que necesites. Elegí 9.0.115 como ejemplo porque esa es la versión que agregó el soporte h.264.

Si el visitante no tiene flash, informará una versión flash de " 0.0.0 " ;, por lo que si solo quiere saber si tiene flash, use:

if(swfobject.hasFlashPlayerVersion("1"))
{
    alert("You have flash!");
}
else
{
    alert("You do not flash :-(");
}

Sé que este es un post antiguo, pero he estado buscando por un tiempo y no encontré nada.
He implementado la Biblioteca de Detección de Flash de JavaScript . Funciona muy bien y está documentado para un uso rápido. Literalmente me tomó 2 minutos. Aquí está el código que escribí en el encabezado:

<script src="Scripts/flash_detect.js"></script>
<script type="text/javascript"> 
 if (!FlashDetect.installed) {
    alert("Flash is required to enjoy this site.");         
 } else {
    alert("Flash is installed on your Web browser.");
 }
</script>        

Puede utilizar compilador de cierre para generar una pequeña detección de flash en todos los navegadores:

// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// @formatting pretty_print
// @use_closure_library true
// ==/ClosureCompiler==

// ADD YOUR CODE HERE
goog.require('goog.userAgent.flash');
if (goog.userAgent.flash.HAS_FLASH) {
    alert('flash version: '+goog.userAgent.flash.VERSION);
}else{
    alert('no flash found');
}

que da como resultado lo siguiente " compilado " código:

var a = !1,
    b = "";

function c(d) {
    d = d.match(/[\d]+/g);
    d.length = 3;
    return d.join(".")
}
if (navigator.plugins && navigator.plugins.length) {
    var e = navigator.plugins["Shockwave Flash"];
    e && (a = !0, e.description && (b = c(e.description)));
    navigator.plugins["Shockwave Flash 2.0"] && (a = !0, b = "2.0.0.11")
} else {
    if (navigator.mimeTypes && navigator.mimeTypes.length) {
        var f = navigator.mimeTypes["application/x-shockwave-flash"];
        (a = f && f.enabledPlugin) && (b = c(f.enabledPlugin.description))
    } else {
        try {
            var g = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"),
                a = !0,
                b = c(g.GetVariable("$version"))
        } catch (h) {
            try {
                g = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"), a = !0, b = "6.0.21"
            } catch (i) {
                try {
                    g = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"), a = !0, b = c(g.GetVariable("$version"))
                } catch (j) {}
            }
        }
    }
}
var k = b;
a ? alert("flash version: " + k) : alert("no flash found");

Versión mínima que he usado (no verifica la versión, solo Flash Plugin):

var hasFlash = function() {
    return (typeof navigator.plugins == "undefined" || navigator.plugins.length == 0) ? !!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) : navigator.plugins["Shockwave Flash"];
};

Biblioteca de detección de flash de JavaScript de Carl Yestrau, aquí:

http://www.featureblend.com/javascript-flash-detection-library.html

... puede ser lo que estás buscando.

¿Quizás el kit de detección de flash player de adobe podría ser útil aquí?

http://www.adobe.com/products/flashplayer/download/detection_kit /

Detectar e incrustar Flash en un documento web es una tarea sorprendentemente difícil.

Me sentí muy decepcionado con el marcado de calidad y no conforme con los estándares generado tanto por SWFObject como por las soluciones de Adobe. Además, mis pruebas encontraron que el actualizador automático de Adobe es incoherente y poco confiable.

La biblioteca de detección de flash de JavaScript (Flash Detect) y JavaScript Flash HTML Generator Library (Flash TML) es una solución de marcado legible y que cumple con los estándares .

- " ¡Luke leyó la fuente! "

Código para una línea isFlashExists variable:

<script type='text/javascript'
    src='//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js'> </script>

<script type='text/javascript'>
   var isFlashExists = swfobject.hasFlashPlayerVersion('1') ? true : false ;
   if (isFlashExists) {
    alert ('flash exists');
   } else {
    alert ('NO flash');
   }
</script>

Tenga en cuenta que hay una alternativa como esta: swfobject.getFlashPlayerVersion();

Vea la fuente en http://whatsmy.browsersize.com (líneas 14-120).

Aquí está el resumen del navegador cruzado código en jsbin para detección de flash solamente , funciona en: FF / IE / Safari / Opera / Chrome.

¿qué pasa con:

var hasFlash = function() {
    var flash = false;
    try{
        if(new ActiveXObject('ShockwaveFlash.ShockwaveFlash')){
            flash=true;
        }
    }catch(e){
        if(navigator.mimeTypes ['application/x-shockwave-flash'] !== undefined){
            flash=true;
        }
    }
    return flash;
};

Si está interesado en una solución de JavaScript puro, aquí está la que copio de Brett :

function detectflash(){
    if (navigator.plugins != null && navigator.plugins.length > 0){
        return navigator.plugins["Shockwave Flash"] && true;
    }
    if(~navigator.userAgent.toLowerCase().indexOf("webtv")){
        return true;
    }
    if(~navigator.appVersion.indexOf("MSIE") && !~navigator.userAgent.indexOf("Opera")){
        try{
            return new ActiveXObject("ShockwaveFlash.ShockwaveFlash") && true;
        } catch(e){}
    }
    return false;
}

Si solo quería comprobar si Flash está habilitado, esto debería ser suficiente.

function testFlash() {

    var support = false;

    //IE only
    if("ActiveXObject" in window) {

        try{
            support = !!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"));
        }catch(e){
            support = false;
        }

    //W3C, better support in legacy browser
    } else {

        support = !!navigator.mimeTypes['application/x-shockwave-flash'];

    }

    return support;

}

Nota: evite marcar enabledPlugin , algunos navegadores móviles tienen el plugin de flash de pulsar para habilitar y activarán un falso negativo.

Para crear un objeto Flash compatible con standart (sin embargo, con JavaScript), te recomiendo que eches un vistazo

Objetos Flash no intrusivos (OVNI)

http://www.bobbyvandersluis.com/ufo/index.html

Han creado un pequeño .swf que redirige. Si el navegador está habilitado para flash, se redireccionará.

package com.play48.modules.standalone.util;

import flash.net.URLRequest;


class Redirect {


static function main() {

    flash.Lib.getURL(new URLRequest("http://play48.com/flash.html"), "_self");

}

}

Usando esta compilación de Google Closure goog.require ('goog.userAgent.flash'), creé estas 2 funciones.

booleano hasFlash ()

Devuelve si el navegador tiene flash.

function hasFlash(){
    var b = !1;
    function c(a) {if (a = a.match(/[\d]+/g)) {a.length = 3;}}
    (function() {
    if (navigator.plugins && navigator.plugins.length) {
        var a = navigator.plugins["Shockwave Flash"];
        if (a && (b = !0, a.description)) {c(a.description);return;}
        if (navigator.plugins["Shockwave Flash 2.0"]) {b = !0;return;}
    }
    if (navigator.mimeTypes && navigator.mimeTypes.length && (a = navigator.mimeTypes["application/x-shockwave-flash"], b = !(!a || !a.enabledPlugin))) {c(a.enabledPlugin.description);return;}
    if ("undefined" != typeof ActiveXObject) {
        try {
            var d = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");b = !0;c(d.GetVariable("$version"));return;
        } catch (e) {}
        try {
            d = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");b = !0;
            return;
        } catch (e) {}
        try {
            d = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"), b = !0, c(d.GetVariable("$version"));
        } catch (e) {}
    }
    })();
    return b;
}

boolean isFlashVersion (versión)

Devuelve si la versión flash es mayor que la versión provista

function isFlashVersion(version) {
    var e = String.prototype.trim ? function(a) {return a.trim()} : function(a) {return /^[\s\xa0]*([\s\S]*?)[\s\xa0]*$/.exec(a)[1]};
    function f(a, b) {return a < b ? -1 : a > b ? 1 : 0};
    var h = !1,l = "";
    function m(a) {a = a.match(/[\d]+/g);if (!a) {return ""}a.length = 3;return a.join(".")}
    (function() {
        if (navigator.plugins && navigator.plugins.length) {
            var a = navigator.plugins["Shockwave Flash"];
            if (a && (h = !0, a.description)) {l = m(a.description);return}
            if (navigator.plugins["Shockwave Flash 2.0"]) {h = !0;l = "2.0.0.11";return}
        }
        if (navigator.mimeTypes && navigator.mimeTypes.length && (a = navigator.mimeTypes["application/x-shockwave-flash"], h = !(!a || !a.enabledPlugin))) {l = m(a.enabledPlugin.description);return}
        if ("undefined" != typeof ActiveXObject) {
            try {
                var b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");h = !0;l = m(b.GetVariable("$version"));return
            } catch (g) {}
            try {
                b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");h = !0;l = "6.0.21";return
            } catch (g) {}
            try {
                b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"), h = !0, l = m(b.GetVariable("$version"))
            } catch (g) {}
        }
    })();
    var n = l;
    return (function(a) {
        var b = 0,g = e(String(n)).split(".");
        a = e(String(a)).split(".");
        for (var p = Math.max(g.length, a.length), k = 0; 0 == b && k < p; k++) {
            var c = g[k] || "",d = a[k] || "";
            do {
                c = /(\d*)(\D*)(.*)/.exec(c) || ["", "", "", ""];d = /(\d*)(\D*)(.*)/.exec(d) || ["", "", "", ""];
                if (0 == c[0].length && 0 == d[0].length) {break}
                b = f(0 == c[1].length ? 0 : parseInt(c[1], 10), 0 == d[1].length ? 0 : parseInt(d[1], 10)) || f(0 == c[2].length, 0 == d[2].length) || f(c[2], d[2]);c = c[3];d = d[3]
            } while (0 == b);
        }
        return 0 <= b
    })(version)
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top