...

View Full Version : redirect based on button click and cookie to keep it perminant?



knight202
11-16-2010, 06:03 AM
Hello,


Im looking for a script where i can have people come to my websites index page, watch a short video and learn about what my site is about, then click a button called "always skip to "my website here" " so once they click that button, they will always be directed to my main website when they return.

I belive it will need to be done with cookies aswell?

Thanks
Chris,

Philip M
11-16-2010, 08:22 AM
Here you are, but cookies have been covered very many times in this forum. Did you try using the Search feature?


<html>
<head>

<script type = "text/javascript">

var expDate = new Date();
expDate.setTime(expDate.getTime()+365*24*60*60*1000); // one year ahead or adjust to suit

function setCookie(isName,isValue,dExpires) {
document.cookie = isName + "=" + isValue + ";expires=" + dExpires.toGMTString() + "path=/";
alert ("Cookie Set"); // for testing
}

function getCookie(isName){
cookieStr = document.cookie;
startSlice = cookieStr.indexOf(isName+"=");
if (startSlice == -1) {return false}
endSlice = cookieStr.indexOf(";",startSlice+1)
if (endSlice == -1){endSlice = cookieStr.length}
isData = cookieStr.substring(startSlice,endSlice)
isValue = isData.substring(isData.indexOf("=")+1,isData.length);
return isValue;
}

function dispCookie(isName) {
nValue = getCookie(isName);
alert(nValue); // for testing
if (nValue == "Skip") {
window.location = "mymainpage.html"; // redirect to the main page if cookie found
}
}

function deleteCookie(isName){
if (getCookie(isName)){
document.cookie = isName + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

</script>
</head>

<body onload = dispCookie('skipCookie')>

<input type = "button" value = 'Skip the video in future' onclick = "setCookie('skipCookie','Skip',expDate)">

</body>
</html>


Quizmaster: Which way does the profile of the Queen always face on a coin?
Contestant: Is it North?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum