Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    redirect based on button click and cookie to keep it perminant?

    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,

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Here you are, but cookies have been covered very many times in this forum. Did you try using the Search feature?

    Code:
    <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?
    Last edited by Philip M; 11-16-2010 at 10:26 AM. Reason: Noticed typo


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •