Swelen Labs

Labs and Gadgets
Swelen Advertising
Releases / SWF Inject 1.2
Project Name : SWFInject 1.2
Author : Vincent Fontaine
License : MIT License
Date : 2012-03-02

swfinject.js (1203 bytes)

Swelen SWF Inject 1.2 : Insert SWF into HTML

World's smallest JavaScript solution to insert Flash Movies into the DOM of a web page.
  • Light-weight, petit tiny winy size, very small : 1 210 1 203 bytes uncompressed (0.6KB gzip)
  • Only one line JavaScript invocation
  • JSON for Params and FlashVars
  • Flash Detection method included
  • Open Source MIT License, feel free to use and modify
  • Cross-Browser (Tested and work on IE6+, Opera 8+, FireFox, Chrome)
  • Compact but pretty readable code using no compression
  • Can be used as an alternative solution to SWFObject and UFO



Usage : mySWF = new SWFInject( DivID, Filename, FlashID, Width, Height, FlashVersionNeeded, Params, Flashvars );
<div id="InjectHere"></div>

<script type="text/javascript">
    var mySWF = new SWFInject('InjectHere', 'demo.swf', 'FlashID', 300, 250, 8, {wmode:"transparent", quality:"high"}, {});


Demo : See it in action

The following SWF was injected into this web page by SWF Inject


Using JSON to send FlashVars and Params

Using JavaScript Object Notation (JSON) to send Params and FlashVars
<div id="InjectHere"></div>

<script type="text/javascript">

var flashvars = {
    name1 : "hello",
    name2 : "world",
    name3 : "foobar"

var params = {
    wmode : "transparent",
    quality : "high",
    bgcolor : "#ffffff"

var mySWF = new SWFInject('InjectHere', 'demo.swf', 'FlashID', 300, 250, 8, params, flashvars);



Flash Detection using the Check() method

And what if Flash Player is not installed on the client's browser ?
SWF Inject does not provide Express Install to keep its size very small, but you can check if a specific version of Flash is installed on the client's browser.

<div id="InjectHere"></div>

<script type="text/javascript">
    mySWF = new SWFInject('InjectHere', 'demo.swf', 'FlashID', 300, 250, 9, {}, {});
    alert( mySWF.Check(9) ); // test if client's browser is ready for at least Flash 9