swfobject with <embed> tag.
A couple of the people I work with have trouble using the swfobject script, I think javascript just intimidates them or something. So I wrote a simple little jquery script that automatically converts an <embed> tag into a swfobject embed.
This probably would have been more useful 2-3 years ago when the active x issue was a big deal, but I figured it could still be useful for some people.
Here's the code:
-
$(document).ready(function(){
$("embed.flash").each(function(){
$.divTarget = $(this).attr("target");
var so = new SWFObject($(this).attr("src"), "flashFlipper", $(this).attr("width"), $(this).attr("height"), "8", "#ffffff");
so.addParam("wmode", "transparent");
$(this).replaceWith("<div id='" + $.divTarget + "'></div>");
so.write($.divTarget);
});
})
With this, you can just add the following html and it'll automatically write in the swfobject:
-
<embed src="/file.swf" class="flash" width="800" height="600" target="divID"/>
This works fine as it is, but a couple things might help it that I haven't done yet.
1.) Does anyone know of a better attribute tag to use than target? I don't think this would currently pass validation since target isn't a valid embed attribute.
2.) Any idea how to append the <script type="text/javascript" src="/swfobject.js"></script> using this script? I'm getting an ASP error not allowing nexted <script> tags, even if it's inside of a .append function. This would be better than having to manually add the swfobject.js to the head.