1

Ok, I know how to register my js file in my html and call functions in the .js from my html file. Here I am trying to do the opposite , I have a function in the .js file and I want to call a function that is in my html file. How do I go about registering the html (it's actually .aspx ) but that really shouldn't matter for the scope of this question.

1
  • what's the problem you encounter? you should be able to call it directly as long as the function in your html parsed first! Commented Aug 31, 2012 at 6:53

2 Answers 2

2

Just make sure that the JavaScript function in your HTML is defined on the page before the code in the .js include calls it.

Sign up to request clarification or add additional context in comments.

Comments

2

Simply include your external script to the page at the end your body tag or at any place after your function declaration.

Aspx page:

<body>
    content content
     <script>
        /* Function to be called */
        function s(){
           alert('Hello World!');
        }
     </script>
     <script src="myJS.js"></script>
</body>

myJS.js:

/* Call a page function */
s();

By the time your external file is loaded your function s() will be declared.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.