»
Tiếng AnhTiếng PhápTiếng Việt

In - Dùng cookie - JavaScriptBank.com

Phiên bản đầy đủ: jsB@nk » Cookie » Dùng cookie
URL: https://www.javascriptbank.com/feeling-lucky.html

Dùng cookie © JavaScriptBank.comĐoạn mã này hiển thị một nút nhấn cho phép người dùng di chuyển ngẫu nhiên đến các địa chỉ. Mỗi khi người dùng đã đi đến một địa chỉ, đoạn mã JavaScript sẽ dùng cookie để lưu lại và sẽ không chọn địa chỉ này trong lần di chuyển kết tiếp.

Phiên bản đầy đủ: jsB@nk » Cookie » Dùng cookie
URL: https://www.javascriptbank.com/feeling-lucky.html



JavaScript
<script language="javascript">// Created by: Will Bontrager :: http://www.bontragerconnection.com/// Leave next line as is.var Lucky = new Array();// The cookie to keep track of which "lucky" destinations // have already been visited needs a name. Okay to change//  the cookie name.var FeelLuckyCookieName = "FeelLuckyCookie";// When a "lucky" destination has been decided upon, shall // the browser open a new window with the desitination URL?// (Specify "y" or "yes" if yes new window; otherwise "".)var NewWindow = "y";// Specify your lucky destination URLs here. The first is // assigned to Lucky[0], the next to Lucky[1], and so // forth, in numerical sequence -- as many as you want.Lucky[0] = "http://javascriptbank.com/javascript/";Lucky[1] = "http://javascriptbank.com/javascript/";Lucky[2] = "http://javascriptbank.com/javascript/";Lucky[3] = "http://javascriptbank.com/javascript/";// No additional JavaScript customizations are required. //var TabChar = String.fromCharCode(9);var CurrentCookie = '';function GetLuckyCookie() {  var cookiecontent = '';  if(document.cookie.length > 0) {   var cookiename = FeelLuckyCookieName + '=';   var cookiebegin = document.cookie.indexOf(cookiename);   var cookieend = 0;   if(cookiebegin > -1) {     cookiebegin  += cookiename.length;     cookieend = document.cookie.indexOf(";",cookiebegin);     if(cookieend < cookiebegin) { cookieend = document.cookie.length; }     cookiecontent = document.cookie.substring(cookiebegin,cookieend);    }  }  return cookiecontent;}function PutLuckyCookie(value) {  if(CurrentCookie.length > 0) { value = CurrentCookie + TabChar + value; }  value = escape(value);  document.cookie = FeelLuckyCookieName + "=" + value;}function YesMakeMeLucky() {   CurrentCookie = GetLuckyCookie();  CurrentCookie = unescape(CurrentCookie);  if(CurrentCookie == '.') { CurrentCookie = ''; }  var LuckyVisitedList = CurrentCookie.split(TabChar);  if(LuckyVisitedList.length >= Lucky.length) {   document.cookie = FeelLuckyCookieName + "=.";   CurrentCookie = '';   LuckyVisitedList = Array();  }  for(var i = 0; i < LuckyVisitedList.length; i++) { Lucky[LuckyVisitedList[i]] = ''; }  var LuckyL = new Array();  for(var i = 0; i < Lucky.length; i++) {   if(Lucky[i].length > 0) { LuckyL.push('' + i + TabChar + Lucky[i]); }  }  var LuckyDestinationNumber = 0;  if(LuckyL.length > 1) { LuckyDestinationNumber = Math.ceil((Math.random() * LuckyL.length) - 1); }  var LuckyNumberPlace = new Array();  LuckyNumberPlace = LuckyL[LuckyDestinationNumber].split(TabChar);  PutLuckyCookie(LuckyNumberPlace[0]);  NewWindow = NewWindow.toLowerCase();  if(NewWindow.substr(0,1) == "y") { window.open(LuckyNumberPlace[1]); }  else { document.location = LuckyNumberPlace[1]; }}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form>  <input type="button" onclick="YesMakeMeLucky()" value="Yes, I feel lucky!"><br></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->