To call a JavaScript function when an HTML page loads, use the code below:
[sourcecode language=”JavaScript”] <!DOCTYPE html><html>
<head>
<script>
function HelloWorld() {
document.write("Hello World");
}
</script>
</head>
<body onload="HelloWorld()">
</body>
</html>
[/sourcecode]
This displays:
![]()
And if using a DIV:
[sourcecode language=”JavaScript”]
<!DOCTYPE html>
<html>
<head>
<script>
function HelloWorld() {
document.getElementById("MyDiv").innerHTML = "Hello World!";
}
</script>
</head>
<body onload="HelloWorld()">
<div id="MyDiv"></div>
</body>
</html>
[/sourcecode]
Which Displays:
![]()

Keep learning. Keep building.
Explore AI, agents & Microsoft technology.
I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.
Subscribe on YouTube →Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert
