Question

Quelqu'un a-t-il un exemple de script qui fonctionne correctement avec IE / Firefox pour détecter si le navigateur est capable d'afficher du contenu Flash intégré? Je dis de manière fiable parce que je sais que ce n'est pas possible 100% du temps.

Était-ce utile?

La solution

SWFObject est très fiable. Je l’utilise sans problème depuis longtemps.

Autres conseils

Je suis d'accord avec Max Stewart . SWFObject est la voie à suivre. J'aimerais compléter sa réponse par un exemple de code. Cela devrait vous aider à démarrer:

Assurez-vous d'avoir inclus le fichier swfobject.js (obtenez-le ici. ):

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

Ensuite, utilisez-le comme suit:

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");
}

Remplacer "9.0.115" avec la version flash minimale dont vous avez besoin. J'ai choisi 9.0.115 comme exemple car c'est la version qui a ajouté le support de h.264.

Si le visiteur n'a pas flash, il signalera une version flash de "0.0.0", donc si vous voulez juste savoir s'il en existe, utilisez:

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

Je sais que c'est un ancien billet, mais cela fait longtemps que je cherche et je n'ai rien trouvé.
J'ai implémenté la bibliothèque de détection JavaScript Flash . Cela fonctionne très bien et est documenté pour une utilisation rapide. Cela m'a pris littéralement 2 minutes. Voici le code que j'ai écrit dans l'en-tête:

<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>        

Vous pouvez utiliser le compilateur de fermeture pour générer une petite détection du flash entre les navigateurs:

// ==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');
}

: "& compile "" code:

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");

Version minimale que j'ai jamais utilisée (ne vérifie pas la version, mais uniquement le plug-in Flash):

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

Bibliothèque de détection Flash JavaScript de Carl Yestrau, ici:

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

... peut être ce que vous cherchez.

Peut-être que le kit de détection d’adobe player d’adobe pourrait être utile ici?

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

La détection et l'intégration de Flash dans un document Web est une tâche étonnamment difficile.

J'ai été très déçu par la qualité et le balisage non conforme aux normes généré à la fois par les solutions SWFObject et Adobe. De plus, mes tests ont révélé que le programme de mise à jour automatique d’Adobe était incohérent et peu fiable.

Bibliothèque de détection Flash de Flash (Détection de Flash) et La bibliothèque JavaScript Flash HTML Generator (Flash TML) est une solution de balisage lisible, maintenable et conforme aux normes. .

- "Luke a lu la source!"

Code pour une couche 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>

Notez qu'il existe une alternative comme celle-ci: swfobject.getFlashPlayerVersion ();

Voir la source sur http://whatsmy.browsersize.com (lignes 14 à 120).

Voici le résumé du navigateur multi-navigateur code sur jsbin pour la détection de flash uniquement fonctionne sur: FF / IE / Safari / Opera / Chrome.

qu'en est-il:

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 vous êtes intéressé par une solution purement Javascript, voici celle que je copie depuis 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 vous voulez juste vérifier si le flash est activé, cela devrait suffire.

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;

}

Remarque: évitez de cocher enabledPlugin , car certains navigateurs mobiles disposent d'un plug-in flash à activer et déclenchent des faux négatifs.

Pour créer un objet Flash conforme à la norme standart (avec JavaScript cependant), je vous recommande de consulter

Objets flash discrets (UFO)

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

Vous avez créé un petit .swf qui redirige. Si le navigateur est activé flash, il sera redirigé.

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");

}

}

Utilisation de la bibliothèque goog.require ('goog.userAgent.flash') du compilateur Google Closure, j'ai créé ces 2 fonctions.

Booléen hasFlash ()

Renvoie si le navigateur a 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 (version)

Renvoie si la version flash est supérieure à la version fournie

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)
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top