Sunday, December 9, 2007

Writing to the statusbar

Writing to the statusbar

Now I want to show you how to write text to the statusbar (the bar on the bottom of your browser where the URLs are shown) and of course I will explain how a scroller works- although they are already hated in the JavaScript scene (I tell you why later on). At first how is the statusbar 'addressed' ? This script shows you how one can write a simple text to the statusbar:

We create two buttons which call both the function statbar(txt). The txt in the brackets shows that the function gets a variable passed over from the function call. (I called this just txt- it could as well be anything totaly different.) When you look at the

tag where the buttons are created you can see that the function statbar(txt) is called. But we don't write txt there. We just put the text there we want the browser to show in the statusbar. You can see it this way: The function is called and defines the variable txt- it gets the 'value' you passed over by the function call. So when pressing the 'Write!' button the statbar(txt) function is called and txt stores the string 'Hi! This is the statusbar'. You can now use the variable txt as usual.

This method of passing variables to a function makes the function very flexible. Look at the second button. It calls the same function. Without variable passing we would need 2 different functions. Now what does the function statbar(txt) do? Well this is simple. You just write the contents of txt to the variable window.status. This is done by window.status = txt;. Writing an empty string ('') to the statusbar erases it. Notice that we have to use these single quotes ' because we use double quotes " for defining onClick. The browser needs to know which quotes belong together- so you have to alternate with single and double quotes. I think this is quite clear.

No comments: