Socket
Socket
Sign inDemoInstall

flashdetect

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    flashdetect

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


Version published
Weekly downloads
11
increased by120%
Maintainers
1
Install size
5.34 kB
Created
Weekly downloads
 

Readme

Source

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.

FAQs

Last updated on 09 Nov 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc