It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

call different js file from JavaScript

call different js file from JavaScript

Postby nitron96 on Thu Jun 10, 2010 1:45 am

I am trying to use a variable to call a JavaScript file but I have had no luck getting to actually work my current code is this:
Code: Select all
      <script type="text/javascript">
      data=window.location.search;
      if (data.substring(0, 1) == '?') {
         data = data.substring(1);
      }
      
      function staticLoadScript(data)
      {
         document.write(data);
         document.write('<script src="js/', data, '" type="text/JavaScript"><\/script>');
      }
      staticLoadScript(data);
      
      document.write(data)

   </script>

my data variable has somedata.js and I need to load that js file
any and all help will be greatly appreciated, thanks!
nitron96
 
Posts: 3
Joined: Thu Jun 10, 2010 1:32 am

Re: call different js file from JavaScript

Postby Logician on Fri Jun 18, 2010 2:05 am

Assuming that your querystring is in the form: myurl?myfile.js

Code: Select all
document.write( '<script src="' + data + '" type="text/JavaScript"><\/script>' );
Logician
 
Posts: 20
Joined: Tue Jun 12, 2007 3:43 am
Location: U.K.

Re: call different js file from JavaScript

Postby nitron96 on Sat Jun 19, 2010 12:00 am

Thanks for the reply, but my biggest problem is that I can't use arrays. Thanks.
nitron96
 
Posts: 3
Joined: Thu Jun 10, 2010 1:32 am


Who is online

Users browsing this forum: No registered users and 4 guests