Hi all,
I know this is almost definitely the 'wrong' answer in the sense that there are better ways of achieving the end result, but there is nothing to stop you putting <script src="myjavascriptfile.js" type="text/javascript"></script> directly into a Text/HTML module. Just switch to source view before you enter the text otherwise the raw HTML will get HTMLEncoded and appear as literal text.
When I want to have some javascript loaded for a page I usually create a custom module to do the work for me. All you need in the modules PageLoad event handler is something like this (code in C#);
try
{
if (!ClientAPI.IsClientScriptBlockRegistered(this.Page, "myjavascriptfile.js"))
{
ClientAPI.RegisterClientScriptBlock(this.Page, "myjavascriptfile.js", "<script type=\"text/javascript\" src=\"/mypath/myjavascriptfile.js\"></script>");
ClientAPI.RegisterStartUpScript(this.Page, "", "<script type=\"text/javascript\">myjavascriptfile_init();</script>");
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
This code links in the JavaScript file /mypath/myjavascriptfile.js if it is not already linked and sets the function myjavascriptfile_init() to call once the page has loaded. Once I've created the module I can just add it to whichever pages need the JavaScript. If this isn't the best way to get a module to link in JavaScript I hope someone will correct me.
Hope this is enough to get you all going.
Rhys.