I am working with the chrome browser on a linux system, and have a linux hosted website using the almost universal apache webserver. I use the vim editor to edit the html and javascript files on my web server, and I edit them live which scares some people but actually works just fine.
Alternately, if you don't have a handy web server like I do, you could put these files in your home directory and aim your browser at them using a URL such as file://simple.html.
The reason is that most (maybe all) browsers will load a ".js" file once the first time they encounter it. Then you will edit the file and wonder why your changes aren't working. The browser is still stuck on that first copy of the file it encountered!!
While this is great for performance on a stable website, it is a huge pain in the ass for a developer, There seems to be no easy workaround for this. Even restarting the browser does not solve the problem.
What I do is to put the file "hello.html" on my server, include the javascript inside of "script" tags and aim my browser at that page. The following simple file was the first thing that actually worked. It is not quite the "hello world" application that I wanted, as it uses the "alert" function which may not be included in all javascript implementations.
Note that if you click on the above link, it will run my code. You should get a popup with the hello world message. You will need to use the right mouse button to get a menu, and select "view page source" to see the source.Here is another way, using document.write rather than alert. This simply adds the message to the document. Where in the document? I depends on where the script tags are.
And here is a significanctly more complex, but realistic version of hello world. Here you must click a button to see the greeting.
This is worth some study. We use a form to enclose a button, as is required by html. The button has an "onclick" which actually specifies a bit of javascript in quotes. This bit of javascript just calls a function "myfunc" which is in the script section. This is a typical bit of "event driven programming". Something happens (namely the user clicks on a button) and some code is specified to handle the event.An html "div" provides a place with a name to receive the text generated by the javascript. The javascript code in the myfunc function uses the document.getElementById("greeting") function to find this place and then sets the "innerHTML" attribute of this thing to the text we want to see.
Adventures in Computing / [email protected]