Call a JavaScript file into html

Hi all,

I have a java function stored in java.js.

I would like to call it into my html so that it can execute.

How does one go about this?


It sounds like you are talking about a JavaScript file, not a Java file. I am going to take the liberty of retitling this topic and moving it to the JavaScript category. If I am wrong, just yell!!!

You will have to tell us much more about your code and about the JavaScript file before we can be of any help. A good way to do this is to post your code in a CodePen or JSFiddle so it demonstrates how you expect the code to work. Another way is to create a “working page” that contains that contains and references all of the elements needed to render the page in our browsers.

Bottom line is that we need more information to provide satisfactory help. Show us your HTML and show us your JS.


Assuming you mean JavaScript (not Java):

    <meta chraset="utf-8">
    <title>My Page</title>
    <script src="path/to/the/javascript/file.js"></script>

and in your JS file:

function sayHello(){

Open the HTML file in your browser and you should see the alert.

1 Like

That is what I was looking for. Many thanks for this

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.