Michele Basso
a- a+

PopUp che appare all'uscita o alla chiusura della pagina

Utilizzando il gestore di eventi onUnload,possiamo inserire un popup che si apre quando si chiude lafinestra o quando si cambia pagina.

L'utilizzo dello script è molto semplice; copiamoquesto codice all'interno del tag body:

<SCRIPT LANGUAGE="JavaScript"><!----- Script copyright ©  1997  S.Chris Brown (Spikeman)   http://www.geocities.com/BourbonStreet/3843-->/********************************************************** S.Christopher Brown's (Spikeman)'s****java script bye bye window   ****    copyright © 1997 S.Chris Brown (Spikeman)  ****    spikeman@myself.com****   http://www.geocities.com/BourbonStreet/3843 ****   All Rights Reserved ****  You can freely use this script, if this credit is  ****     included in the source. This Script is for****   noncommercial use only. and has been placed in    ****   The public domain and no fees can be charged in   ****     conjunction with distribution or use.     ****Thank you  ** ********************************************************/ // This JavaScript code Originally by S.Chris Brown  (Spikeman) 1997 ( http://www.geocities.com/BourbonStreet/3843 )    // in the document.writeln you can write anything i happen to put image banners// for my site in the script but you can change that to read anything.// this goodbye window was made so when someone was leaving your site it would// give you a "popup window" saying bye . with the setTimeout it will time// out and close the window. i have it set to 20000 BUT you can change that// i set it that high so the images would have time to load. // make sure it is on UNLOAD so when it is leaving your page it will turn on// and not before ... IF you are going to be adding some document.writeln 's// make sure it sayz windowLeaving.document.writeln so it knows its to the// window leaving and not the main window.function byebyewin(){windowLeaving=window.open("popup.html" ,'Leaving','toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=1,width=420,height=250');}//----------End Of Spikeman Bye bye Window-----></SCRIPT>

Nella penultima riga, possiamo decidere le caratteristichedel nostro popup; in particolare, dobbiamo modificare il nomedel file della pagina che si aprirà all'internodel popup(nell'esempio èpopup.html).

Per attivare lo script, aggiungiamo al tagbody l'attributoonUnload, in questo modo:

<BODY onunload="byebyewin()">

Per problemi relativi all'utilizzo di questo script,potete consultare il nostro forum didiscussione.