1

I have a function in my separate js file called hello().

On my page I have this js:

<script type='text/javascript'>//do hello fnc</script>

How can I get the on page script to call the function in my main js file?

0

3 Answers 3

3

Call it in the src attribute of another script tag, before referring to any of its functions in this script.

<script type='text/javascript' src='main.js'></script>
<script type='text/javascript'>
  hello();
  // Anything defined in previously included js files like main.js
  // is now available, as well as anything defined on this page.
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

as a sidenote type='text/javascript' is no longer necessary
0

Load the external file first and call the function:

<script src=external.js></script>
<script>
  hello();
</script>

Comments

0

You just need to include the external js file:

<script type="text/javascript" src="MyOtherFile.js"></script>

And then wherever in you code you want to call the funciton:

<script type="text/javascript">hello();</script>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.