cheap nfl jerseys china cheap nfl jerseys free shipping wholesale nfl jerseys china wholesale jerseys from china cheap nfl jerseys free shipping cheap nfl jerseys for sale cheap jerseys free shipping wholesale nfl jerseys from china cheap nfl jerseys sale cheap nike nfl jerseys china wholesale jerseys free shipping cheap nfl jerseys wholesale wholesale nfl jerseys online cheap nfl jerseys wholesale china jerseys wholesale cheap coach handbags outlet authentic designer handbags cheap coach handbags outlet cheap coach purses outlet discount coach bags coach bags sale coach purse outlet cheap real coach purses coach handbags sale online coach purse outlet michael kors outlet online store cheap michael kors bags cheap michael kors purse michael kors factory outlet online cheap michael kors handbags cheap michael kors purses michael kors bags outlet online cheap michael kors purse michael kors handbags discount


Introduzione a JavaScript
Part 4


La statusbar.

Come � possibile indirizzare del testo nella statusbar ? Lo script che segue mostra come fare:

Ecco il sorgente dello script:


<html>
<head>
<script language="JavaScript">
<!-- Hide
function statbar(txt) {
   window.status = txt;
}
// -->
</script>
</head>
<body>
<form>
<input type="button" name="look" value="Write!" onclick="statbar('Hi! This is the statusbar!');">
<input type="button" name="erase" value="Erase!" onclick="statbar('');">
</form>
</body>
</html>

Sono stati creati due pulsanti, i quali eseguono delle chiamate alla function statbar(txt). Txt nelle parentesi indica la variabile che viene passata alla function. Si pu� notare all'interno del tag <form> come eseguire le chiamate alla function statbar(txt), in realt� non viene passata un variabile vera e propia, ma una stringa di testo, che nel secondo caso (bottone Erase) � vuota e serve per cancellare il contenuto della statusbar.

Timeout function

Abbiamo gi� visto la propriet� onMouseOver nella seconda parte del tutorial:


<a href="tpage.htm" onMouseOver="window.status='ecco un'altro link...'; return true">

� anche possibile impostare un timer in modo da cancellare la scritta sulla statusbar dopo un determinato tempo:

Prova a spostare il puntatore del mouse qui ma non cliccare !

Ecco il sorgente:


<html>
<head>
<script language="JavaScript">
<!-- Hide
function moveover(txt) {
   window.status = txt;
   setTimeout("erase()",1000);
}
function erase() {
   window.status="";
}
// -->
</script>
</head>
<body>
<a href="dontclck.htm" onMouseOver="moveover('Disappearing!');return true;">
link</a>
</body>
</html>

In questo secondo script � stata aggiunta la function erase(), nell'HTML � stato creato un link utilizzando la propiet� onMouseOver. La function moveover(txt) viene chiamata passando la stringa 'Disappearing!'. Alla variabile 'window.status' viene assegnato il contenuto di txt. La stessa cosa accadeva per la function statbar(txt). La function setTimeout(...) invece setta il tempo durante il quale la stringa deve stare visualizzata sulla statusbar e indica che cosa deve accadere allo scadere di questo tempo. Nell'esempio la function erase() viene chiamata dopo 1000 millisecondi (1 secondo).


Testo scorrevole

Ecco lo script:


<html>
<head>
<script language="JavaScript">
<!-- Hide

var scrtxt="Questo � il messaggio che scorre sulla statusbar";
var lentxt=scrtxt.length;
var width=100;
var pos=1-width;

function scroll() {
  pos++;
  var scroller="";
  if (pos==lentxt) {
    pos=1-width;
  }
  if (pos<0) {
    for (var i=1; i<=Math.abs(pos); i++) 
        { scroller=scroller+" ";} 
    scroller=scroller+scrtxt.substring(0,width-i+1); } 
  else { scroller=scroller+scrtxt.substring(pos,width+pos); } 
  window.status=scroller; setTimeout("scroll()",150); } //-->
</script>
</head>
<body onLoad="scroll();return true;">
Inserire qui la vostra pagina
</body>
</html>

Questo scripts utilizza functions o parti di esse che abbiamo gia visto. Le operazioni che vengono fatte all'inizio servono per calcolare le posizioni di partenza, ma non sono importanti per capire come lo script lavora.


Index - Part 1 - Part 2 - Part 3 - Part 5 Part 6 Part 7

Ultimo aggiornamento: