Jump to content

Cookie redirect <script></script>


carefree

Recommended Posts

I want to creat a javascriipt that uses cookies to redirect a signup page.

 

Basicly i can put this into my template and wherever a user enters the site they get redirected to the url.

 

I have this at the moment it works great but i need it so it goes to a html page and not a popup as it is now:

 

<!--
function ScanCookie(variable)
   {
    cook = document.cookie;
    variable += "=";
    place = cook.indexOf(variable,0);
    if (place <= -1)
        return("0" );
    else
       {
        end = cook.indexOf(";",place)
        if (end <= -1) return(unescape(cook.substring(place+variable.length,cook.length)));
        else return(unescape(cook.substring(place+variable.length,end)));
       }
   }
function CreationCookie(nom,valeur,permanent)
   {
    if(permanent)
       {
        dateExp = new Date(2020,11,11);
        dateExp = dateExp.toGMTString();
            ifpermanent = '; expires=' + dateExp + ';';
       }
    else
        ifpermanent = '';
    document.cookie = nom + '=' + escape(valeur) + ifpermanent;
   }
if(ScanCookie("dejapopup" )==0)
   {
    var msg="Please sign confirm entry"
    if(confirm(msg))
        CreationCookie("dejapopup","oui",false)
    else
        window.location.replace('http://www.SITE.com/signup.html');
   }
//-->

 

Thanks :)

Link to comment
Share on other sites

instead of using window.location you can write a meta redirect

 

document.write("<meta http-equiv='refresh' content='5;url=http:www.yoursite.com' />");

 

as long as this is run in the head it should work fine.

 

however if you are want to work with cookies i would suggest using php its alot simpler to use and work with cookies

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.