[Javascript] reassign the script src attribute

Mike Dougherty mdougherty at pbp.com
Wed Aug 17 13:34:12 CDT 2005


Are there any caveats to reassigning a script tag's source attribute?

I have two different function bodies with the same name.  Ex:  Product A uses the SKU() function 
in ProductA.js while Product B uses the SKU() function from ProductB.js - on the live website, 
there will only ever be a single product for each page and the correct script references are made 
while the page is generated.  Now I want to move these objects into our intranet, where they will 
share the same DHTML container.

Is this possible:  (notice the SKU() function is different in each source file)

<script id='productscript' src='productA.js' type='text/javascipt' ></script>
<script type='text/javascript'>
   if(productA){ var myobj = new SKU(); }
   else {
     document.getElementById('productscript').src = 'productB.js' ;
     var myobj = new SKU();
     }
</script>



More information about the Javascript mailing list