GSAnet Banner Swap





to tricks page

Writing to a status line.

Take a closer look at the bottom of your browser window. You should see 'you can write anything in the status line !' line written there. This space at the bottom of the browser is a special area, where system information is written and is usually used to show the loading progress or an URL of a link, etc.

By using JavaScript you can take control over what is written there. Consider the following code:

listing 1
<SCRIPT LANGUAGE="JavaScript">

   <!-- 

          // version check

          browserName = navigator.appName;
          browserVer = parseInt(navigator.appVersion);

           if ( browserName == "Netscape" ) {
           if ( browserVer > 2 ) { version = true; } }
   
           if ( browserName == "Microsoft Internet Explorer" ) {
           if ( browserVer > 2 ) { version = true; } }



	function status_display(status_line)
	{ if (version) {
		window.defaultStatus=status_line;}
	}

	function status_onfly(status_line)
	{ if (version) {
		window.status=status_line;}
	}

      // -->
                            </SCRIPT>

Now, let me explain the code a bit. As always, it starts with a SCRIPT tag. It also uses <!-- and --> comments to hide the script from older browsers that do not understand JavaScript and treat JavaScript commands as text. This is a standard treatment and is considered a "correct" scripting.

Now the technique. window.defaultStatus is a variable that contains what is being displayed when there is no event that leads to a status line being re-written. For example, when Netscape does not display anything at the status string, instead of an empty string it displays "Document Done" message.

window.status is an "on-fly" change. For example when you point to a link, status line displays an URL. This "on-fly" change is made by using window.status variable.

In the code above, we first check the browser version. You should already know how to do this. The only difference from the routine check is that we check if Netscape browser is version higher than two, if it is we assign "true" to version variable. Then we repeat the same step with Microsoft Browser.

Second, we create two envelope procedures (you should know what the envelope procedure is from the previous discussion). One is for window.defaultStatus and it automatically checks for version at the start. Second is for window.status and is similar to the first.

All right, how do we use these procedures? Well, the first one is easy. Just write the below piece of code:

listing 2
<SCRIPT LANGUAGE="JavaScript">
<!--

status_display('this is my default message. Welcome to my cool page! Yeah!');

// -->
</SCRIPT>

I guess, the code is self-explanatory. You can include it anywhere you want, or you can even add the line status_display('this is my default message. Welcome to my cool page! Yeah!'); to the previous piece of code, because you usually only want to change the default status string message once.

Change of "on-fly" status line is only possible using events. The most popular technique is to write a description of a link when you point your mouse over it. This is how you do it:

listing 3
<A HREF="mylink.htm"
OnMouseOver="status_onfly('this is the coolest link! try it!'); return true;">
My Best Link</A>

All right. This is your ordinary normal Anchor, aka <A HREF> tag. What you need to add to your anchor is this line: OnMouseOver="status_onfly('this is the coolest link! try it!'); return true;".

OnMouseOver is a special event handler. As soon as user points over this anchor, everything inside the quotes is executed. And inside the quotes we have our call to status_onfly procedure with a message. The message, because it is a string, also has to be in quotes. But do not mix up the quotes. Use only 'single' quotes inside the attribute and "double" quotes to "contain" the attribute. You will also have to use return true; statement at the end or otherwise status line will not be displayed.

Ok, now test it. Just point over this link:
My Best Link

When creating your own JavaScript code, remember that JavaScript is case sensitive and hence variable version is different from variable Vesion. Just remembering this will save you from many mistakes.

This is it. Now you know how to make use of a status string. But beware of the tendency to overuse it. I personally hate when I cannot see the URL of a link and instead see an "oh so original" message like "this is cool. check this out". The default status line is not that overused, so there is still life in it.

Finally, if you want to display extra information for an image link, you can use IMG ALT attribute. It only works in Microsoft IE, as far as I know, but if you hold your mouse over image for a long time, it will display what you have written in the IMG ALT tag.


©1997 repfect Drug design studio. All Rights Reserved.