tutorial #6 : alert last visit

ok . yg nehh ainna yg mintak . dye cakap mcam mane nk buat yg detect orng tuh first time datang ka and pape jea laa .
ok mari mula .
design > edit layout > add a gadjet > html javacsript
<script type = "text/javascript">
//
var days = 730; // days until cookie expires = 2 years.
var lastvisit=new Object();
var firstvisitmsg="ni lah first time korang mai sini ken?so Welcome!";
lastvisit.subsequentvisitmsg="Welcome back KAWAN! korang ade stalk kat sini haritu pada<b>[displaydate]</b>";

lastvisit.getCookie=function(Name){
var re=new RegExp(Name+"=[^;]+", "i");
if (document.cookie.match(re))
return document.cookie.match(re)[0].split("=")[1];
return'';
}

lastvisit.setCookie=function(name, value, days){
var expireDate = new Date();

var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days));
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

lastvisit.showmessage = function() {
var wh = new Date();
if (lastvisit.getCookie("visitc") == "") {
lastvisit.setCookie("visitc", wh, days);
document.write(firstvisitmsg);
}

else {
var lv = lastvisit.getCookie("visitc");
var lvp = Date.parse(lv);
var now = new Date();
now.setTime(lvp);
var day = new Array("Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat");
var month = new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var dd = now.getDate();
var dy = now.getDay();
dy = day[dy];
var mn = now.getMonth();
mn = month[mn];
yy = now.getFullYear();
var hh = now.getHours();
var ampm = "AM";
if (hh >= 12) {ampm = "PM"}
if (hh >12){hh = hh - 12};
if (hh == 0) {hh = 12}
if (hh < 10) {hh = "0" + hh};
var mins = now.getMinutes();
if (mins < 10) {mins = "0"+ mins}
var secs = now.getSeconds();
if (secs < 10) {secs = "0" + secs}
var dispDate = dy + ", " + mn + " " + dd + ", " + yy + " " + hh + ":" + mins + ":" + secs + " " + ampm
document.write(lastvisit.subsequentvisitmsg.replace("\[displaydate\]", dispDate))
}

lastvisit.setCookie("visitc", wh, days);

}

lastvisit.showmessage();

</script>
Okay , simple kan ? ainna just perlu tukar kan yg warna merah tuh dengan ayat ainna sendiri
That's all . Kemudian save ! :)

20 comments:

mish lily said...

tQ for the tuto...
da lama cari..
:D

apitrawrr said...

@mish lilyyou're ,most welcome xD
hehe

cerite syabusyabu said...

tengs 4 dis tuto apit!..

apitrawrr said...

@cerite syabusyabusure . thanks for dropping by ;)

Moko Ryōko said...
This comment has been removed by the author.
Moko Ryōko said...

sorry salah sent , hehe :]

Moko Ryōko said...

thanks bro :]

Mey amira said...

thanx awak. really appreciate it :)

abeLL the kambing wangi said...

tengs for the tutorr :D

Auji Izra Sygku Dyla said...

waw~~yg ni yg saya cari..terima kasih^^

kieralalala~ said...

dah lamaaa carik . thanks for ur tutor :)

Una said...

thanks apit! ^_^

シmashiEyシ said...

nice tuto !
tengs!

Nur Atiqah said...

Kalau DENIM punya tak blh ke ?

Reen said...

Kenapa tak boleh eh -.-'

Ain said...

kenapa tak boleh :(

ain farahanim said...

kenapa tak boleh :(

Reen said...

tak jadi -.-'

aiNAA kHOdOri said...

akhir nya... pncarian sy sudah pun ber akhir..:)...
thnx 4 your tuto...
nak request skit bley??

mcm na nk tkarkn border blog jdik mlengkung... sblom nih dh try mcm2 dh...
tp, smuanya xmmbuahkn hasill..:(

sorry klau mnyusahkn...

cik qiebaa :) said...

thanks afif,nk try semua tutorial lah kalau boleh :P

Subscribe