GithubHelp home page GithubHelp logo

jeperez / flashdetect-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tylerault/flashdetect

0.0 2.0 0.0 244 KB

Tiny (<1k) Flash detection script distilled from SWFObject

License: MIT License

JavaScript 42.64% HTML 57.36%

flashdetect-1's Introduction

flashdetect

Tiny (<1K) Adobe Flash® Player detection script distilled from SWFObject

Use

Include or load flashdetect.min.js, then call getFlashVersion(). This will always return a number:

  • If the Flash Player plugin is installed, a number denoting the major and minor version is returned, e.g. 9.125 or 11.8
  • If no Flash Player is installed, -1

This usage allows for easy, clean evaluation, like so:

<script src="js/flashdetect.min.js"></script>
<script>
	if( getFlashVersion() >= 9.125 ){
		// Flash approach
	} else {
		// Non-Flash approach
	}
</script>

AMD

If you roll with the cool kids and use a module loader like requirejs, use the flashdetect.amd.js file. The closure will return a function, so you can just do:

require( ['flashdetect.amd'], function(getFlashVersion){
	
	if( getFlashVersion() >= 9 ){
		// Go to town!
	}
	
});

Objective

The goal here is reliable and simple cross-browser Flash detection in as little code as possible.

Reliabile:

The original detection code comes from SWFObject, a Flash embedding library that's been thoroughly vetted and widely used for years. Really, the SWFObject contributors did most of the hard work here and deserve commensurate credit.

Simple:

SWFObject's getFlashPlayerVersion() method returns an object with more detail than is usually needed. Flashdetect always returns a number, so you can more easily pop into an evaluation as described above.

Small:

If you're not sure whether a browser supports Flash, you don't want to load a 10k+ (minified!) script just to find out. What's more, we use Flash in different ways than we used to: mostly for polyfills and enhancements like ZeroClipboard. These libraries tend to come with their own streamlined embedding code, and you may not want to load the polyfill unless you know it's supported.

The minified version of this script is about 600 bytes.

What's changed

Only the vital bits of SWFObject's original detection are retained. Here's what's changed:

  • The 'release' number is gone (3rd value after major & minor versions).
  • Detection via the object element for non-IE browsers is not carried over. See testPlayerVersion() in SWFObject's source for more info.
  • Repeated references and Strings are abstracted to variables for better minification.
  • 'undefined' and null tests are replaced with !!, since all the values are expected as objects.
  • Regular expressions were consolodated.

flashdetect-1's People

Contributors

tylerault avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.