Are you talking about a Javascript function? If so, you can put the text of the function in a seperate file like this:
[tt]
<script type="text/javascript" src="/url/of/file"></script>
[/tt]
If you're talking more generally about taking a file and inserting its contents into multiple web pages, check out SSIs (Server Side Includes). There are a couple of FAQs on this forum which tell you about them.
Just to clarify, the file can have any name you like, but should end in .js (if your server's configured properly it will then send it with the proper MIME type - which is important to some browsers).
It should do. As the browser encounters the <script src=...> tag it loads the javascript from the specified file. It then behaves exactly as if the script had been written inline. So anything that works with an inline script should work with the script in a file.
That said, try to make each file as self-contained as possible. It makes it easier to re-use them in future projects.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.