2. teach you the one or the other useful thing.
Our „hello world“ script will bring up an alert box with the message „Hello world!“:
We got our first function and now we need to call it somehow. As I said already, we will be using the onload() handler.
To make sure that the code works as intended, you have to put the code in the <head> part of your HTML page.
onload="hello_world();" in the opening body tag. Save the page and load it in a browser.
To have a comparison, try my „Hello world“ alert.
onload() handler is useful, but is often abused. I recommend you only use it when you have to. Same applies for the
Better „Hello World!“
If you try it, you will see that
onload() will not work, so we have to use a different approach:
window.onload = hello_world();
Now the script will be executed after everything on the page is loaded.
Wrap up and some hints
I know, if you read this list you will most likely not know how to create the mentioned effects. I suggest you keep this list in mind when I continue with my tutorial because then I will show you some of those things you shouldn’t do just for the purpose of showing it.