dùng JavaScript tạo lời chào tạm biệt khi thoát

Thứ Hai, 4 tháng 6, 2012


Bài viết sau đây sẽ giới thiệu đoạn script tạo lời chào tạm biệt xuất hiện khi một người khách  nào đó tới thăm trang web và rời khỏi trang web của bạn lần đầu tiên. 
Trước tiên bạn hãy chèn đoạn mã sau vào phần <head> trong trang của bạn:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<script>
function openpopup(){
//configure "seeyou.htm and the window dimensions as desired
window.open("seeyou.htm","","width=300,height=338")
};
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
// if cookie exists
offset += search.length;
// set index of beginning of value
end = document.cookie.indexOf(";",offset);
// set index of end of cookie value
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function loadpopup(){
if (get_cookie('popped')==''){
openpopup()
document.cookie="popped=yes"
}
} </script>
Sau đó bạn hãy thêm vào thẻ <body> đoạn mã sau :
<body onunload=”loadpopup()”>
Chúc bạn thành công!
Xem thêm bài viết cùng chuyên mục: ,

Ý kiến bạn đọc [ 0 ]


Ý kiến của bạn