Reputation: 35
I have a .js file that is the javascript translation of a java file.jar. I would like to run the file as soon as the HTML page is loaded. Is it possible? now the file is run using the following code
<div class="w3-twothird" align="center">
<script>
cheerpjInit();
cheerpjCreateDisplay(500,400);
cheerpjRunJar("/app/tesi/homepage/disgrafia.jar");
</script>
</div>
I'd like to use only the js file and not the jar.
Upvotes: 1
Views: 81
Reputation: 66
The simplest way to run a piece of code once a site has loaded is using jQuery's ready()
function.
Goes something like this
$(document).ready(function()
{
//Do the whatever you need to here
});
Do keep in mind, however, that you will need jQuery on your page. Simplest way to get it is using CDN. Just paste this in your <head> </head>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous">
</script>
EDIT: If you don't want to use JQ, you can use an event listener for when the page loads, like so:
document.addEventListener("DOMContentLoaded", function() {
// Code to be executed when the DOM is ready
});
Cheers, hope it helps <3
Upvotes: 2