Direct drupal to script location

In my Drupal site I want to include the swfobject.js script to my pages so added the location in the template.info file:

scripts[] = sites/all/libraries/swfobject/swfobject.js

When I view my pages however, it is added to I guess a default script location, being the following

http://www.mysite.com/sites/all/themes/mytheme

So when I view the source code of my site the complete line becomes:

<script type="text/javascript" src="http://www.mysite.com/sites/all/themes/mytheme/sites/all/libraries/swfobject/swfobject.js?m8l3lo"></script>

How can I point it to the correct location:

http://www.mysite.com/sites/all/libraries/swfobject/swfobject.js

I’ve tried using something like:

scripts[] = ..sites/all/libraries/swfobject/swfobject.js

but those first two dots just get added to that default line:

<script type="text/javascript" src="<strong>http://www.mysite.com/sites/all/themes/mytheme</strong>/..sites/all/libraries/swfobject/swfobject.js?m8l3lo"></script>

Try


scripts[] = /sites/all/libraries/swfobject/swfobject.js

No, that didn’t work. It became:

<script type="text/javascript" src="http://www.mysite/sites/all/themes/mytheme//sites/all/libraries/swfobject/swfobject.js?m8mzzl"></script>

It’s like everything you place behind scripts is just added to the default theme location. In this case it now has two slashes behind www.mysite/sites/all/themes/mytheme.

There doesn’t seem to be a way to have it move up the directory tree when I use scripts?

I now did it by placing a libraries folder inside my theme folder (where the other files/images etc. also are) and direct it simply to that directory. with scripts libraries/swfobject/swfobject.js.

But how is it done with other scripts then which use this libraries folder which is at www.mysite.com/sites/all/libraries? It now has the nivo-slider script in it for example. I thought it might be convenient to place all javascripts in there, but how do they make it direct upwards from mytheme > themes to libraries then?

Oh, I see what you mean… The script line isn’t parsed as a path, it’s a piece of text that is attached to the site root + path to theme and printed to the html template. I didn’t expect that.

It’s not as clean as adding it to the info file but you could add your file directly to html.tpl.php (D7) or add it using a block with the drupal_add_js(); function.

The best method to add third party code like that would be to register it as a library implementing hook_library. Than use the function [url=http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_add_library/7]drupal_add_library() to actually add the library to the request output.