Full version: jsB@nk » Cookie » Feeling Lucky
URL: https://www.javascriptbank.com/feeling-lucky.html
Give your users a chance to be spontaneous! Clicking on the button will re-direct them to a JavaScript link chosen at random. You can specify any number of links, and they can open in the same window or a new one. A JavaScript cookie is used to track which links are visited. The JavaScript cookie is erased when the browser is closed.
Full version: jsB@nk » Cookie » Feeling Lucky
URL: https://www.javascriptbank.com/feeling-lucky.html
<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-->
<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-->