Lab: SWFObject

Using JavaScript to write the swfobject.js link dynamically

A poster in the SWFObject forum wanted to embed a SWF onto a webpage, but wasn't allowed to add external links. In other words, he wasn't allowed to add this bit of code:

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

This meant he couldn't use SWFObject. To get around this limitation, you can use JavaScript to write the JS link dynamically:

<script type="text/javascript">
  document.write('<sc'+'ript');
  document.write(' type="text/javascript"');
  document.write(' src="swfobject.js">');
  document.write('</sc'+'ript>');
</script>

Here's a working example.