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 3 of 3

Thread: cookie redirect

  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    cookie redirect

    Hi, I'm having a problem with cookie redirects. I have to use an external file to handle the redirect (just has to be this way - I know there are other ways to do it but it needs to be in this external file); but this breaks the back button as with back is clicked it kicks back to the redirect script which quickly forwards the user to the same page they are on (you can never go back unless you click it really fast).

    Also, this is an IE-only problem... anyone know of a workaround I can add to this code to let the back button work?

    Thanks!

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    	<title>Check Cookie</title>
    	
    	<script type="text/javascript">
    	// this function gets the cookie, if it exists
    function readCookie(name)
    {
    	var nameEQ = name + "=";
    	var ca = document.cookie.split(';');
    	for(var i=0;i < ca.length;i++)
    	{
    		var c = ca[i];
    		while (c.charAt(0)==' ') c = c.substring(1,c.length);
    		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    	}
    	return null;
    }
    
    var region = readCookie( 'ex_cookie' );
    if (region == null)
    {
    	window.location = "http://www.example.com/Home";
    	}
    else
    {
    	window.location = "http://www.example.com/Home/" + region;
    	}
    
    
    </script>
    
    
    </head>
    
    <body>
    Redirecting...
    </body>
    </html>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    if (region == null)
    {
    	location.replace("http://www.example.com/Home");
    }
    else
    {
    	location.replace("http://www.example.com/Home/" + region);
    }
    That replaces the current page in the history. So if you click the Back button, the page will not go to this page that has this code but to its previous page.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New to the CF scene
    Join Date
    May 2007
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ahhh
    awesome, thanks!


  •  

    Posting Permissions

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