Tech-Funda

…in touch with tomorrow









Javascript Bouncing Message at status bar

Posted by admin on Dec-13-2007

Javascript Bouncing Message at status bar

Here we are going to Bounce Message at status bar of a web browser( IE ).

first of all we are going to take a look on code and then see its working.

Live Demo…

<script language=“javascript” type=“text/javascript”>
// Location of this script:
// http://www.tech-funda.com
//********************************************
//* Javascript Bouncing Message               
//* (c) Chetankumar Digambarrao Akarte,       
//* http://www.tech-funda.com           
//* Created on 03/09/2005                     
//* Use the script freely as long as         
//*           credits are maintained         
//********************************************

var data = ” My  Bouncing  Message … !!!  “// Message to be display
var limit=“                        “;   // define bounce limit
var message1=limit+‘*’+data+‘*’+limit;
var direction = “left”;
var speed = 75;

function bounce()
{
if (direction == “left”)
  {
    message2=message1.substring(2,message1.length)+“  “;
    window.status=message2;
    setTimeout(“bounce();”,speed);
    message1=message2;
    if (message1.substring(0,1) == “*”)
     direction=“right”;
  }
else
  {
    message2=“  “+message1.substring(0,message1.length-2);
    window.status=message2;
    setTimeout(“bounce();”,speed);
    message1=message2;
    if (message1.substring(message1.length-1,message1.length) == “*”)
     direction=“left”;
  }
}
bounce()

</script>

First of all we have define some Variable to store display message and define bouncing limit. Then we add bouncing limit on both side of our message with * in between them. * plays an important role while Bouncing Message at status bar. also we have define speed to control Bouncing and direction of bouncing.

here we have define a functionfunction bounce(). checking value of direction we have perform some opration to bounce our message. For thatjavascript’s substring() Methods plays an important role which allows us to cut substrings out of a string. so here we cut Space from our message and then disply it on status bar and refresh browser.

window.status=message2;
setTimeout(“bounce();”,speed);

as we reach at * we change derection and continue process.

The substr() and substring() Methods—Copying Part of a String

If we wanted to cut out part of a string and assign that cut out part to another variable or use it in an expression, we would use the substr() and substring() methods. Both methods provide the same end result, that is, a part of a string, but they differ in the parameters they require. The method substring() takes two parameters: the character start position and the character end position of the part of the string we want. The second parameter is optional; if you don’t include it, all characters from the start position to the end of the string are included.
For example, if our string is “JavaScript” and we want just the text “Java”, we could call the
method like so:

var myString = “JavaScript”;
var mySubString = myString.substring(0,4);
alert(mySubString);

As with all the methods of the String object so far, the character positions start at zero. However, you might be wondering why we specified the end character as 4. This method is a little confusing because the end character is the end marker; it’s not included in the substring that is cut out. It helps to think of the parameters as specifying the length of the string being returned: the parameters 0 and 4 will return (4 - 0) characters starting at and including the character at position 0. Depicted graphically it looks like this:

0 1 2 3 4 5 6 7 8 - Character Position
J a v a S c r i p - Character

Like substring(), the method substr() again takes two parameters, the first being the start position of the first character you want included in your substring. However, this time the second parameter specifies the length of the string of characters that you want to cut out of the longer string. For example, we could rewrite the preceding code as

var myString = “JavaScript”;
var mySubString = myString.substr(0,4);
alert(mySubString);

As with the substring() method, the second parameter is optional. If you don’t include it, all the characters from the start position onward will be included.

The main reason for using one method rather than the other is that the substring() method is supported by IE 3+ and by NN 2+ browsers. However, the substr() method only works with version 4 (and later) browsers.

Download
Download source code for ‘ Javascript Bouncing Message at status bar ‘

Download


  1. Luke Said,

    I like, very good.

  2. Woroclult Said,

    Hello!
    Nice site ;)
    Bye

  3. nhiem Said,

    it is great
    i like it much
    thank
    bye!
    have a good day11111111111

  4. Marq Said,

    I was just wondering if there is a way to make this script work in the newest version of Internet Explorer! If you could come back to me that would be great.

Add A Comment

*
To prove that you're not a bot, enter this code
Anti-Spam Image