Javascript functions in outside file

E

Erik Abels

I have written several Javascript functions into a single ".js" file for a header that is to be included into every page of an existing website. As of right now i am having to copy the functions into every page and i was wondering if i could call them from that ".js" file. currently it looks something like this

onmouseover="navDrop(ProductDrop, Products)"

how would i call this function if it were located in another file such as headerfunctions.js
 
K

Kevin Spencer

You have to reference the file in a script tag, and then the functions are
available as if they were in the page:

<script source="yourFileName.js"></script>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Erik Abels said:
I have written several Javascript functions into a single ".js" file for a
header that is to be included into every page of an existing website. As of
right now i am having to copy the functions into every page and i was
wondering if i could call them from that ".js" file. currently it looks
something like this
onmouseover="navDrop(ProductDrop, Products)"

how would i call this function if it were located in another file such as
headerfunctions.js
 
S

Stefan B Rusynko

You don't
If the script is already loaded in the HEAD section, the function is available to the page



| where do i put the script source tag in the line onmouseover="functionname()". I tried adding in the quotes but that didn't work
and i can't add it at the begginning and end of the file or the entire file becomes Javascript.
|
| "Kevin Spencer" wrote:
|
| > You have to reference the file in a script tag, and then the functions are
| > available as if they were in the page:
| >
| > <script source="yourFileName.js"></script>
| >
| > --
| > HTH,
| > Kevin Spencer
| > ..Net Developer
| > Microsoft MVP
| > Big things are made up
| > of lots of little things.
| >
| > | > > I have written several Javascript functions into a single ".js" file for a
| > header that is to be included into every page of an existing website. As of
| > right now i am having to copy the functions into every page and i was
| > wondering if i could call them from that ".js" file. currently it looks
| > something like this
| > >
| > > onmouseover="navDrop(ProductDrop, Products)"
| > >
| > > how would i call this function if it were located in another file such as
| > headerfunctions.js
| >
| >
| >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top