SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member ScoobyDan's Avatar
    Join Date
    Sep 2002
    Location
    Sussex, England
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How do I create a redirect using a field?

    Hi,

    I am using a Javascript script to redirect users to their prefered homepage (our site has 3 homepages). The homepage information is stored in a cookie. Here is the redirect script:

    <script language="JavaScript">
    if (document.cookie)
    {
    var home = getCookie("home_page");
    if (home)
    {
    home = eval("http://www.myserver.co.uk/" + home + ".asp");
    window.location = home;
    }
    else
    {
    window.location = "http://www.myserver.co.uk/select.asp";
    }
    }
    else
    {
    window.location = "http://www.myserver.co.uk/select.asp";
    }
    </script>


    When I view the page, I get an error saying 'page http://www.myserver.co.uk/undefined does not exist'. If I insert a 'document.write(home)' line into the code, it outputs what is in the cookie, so that part is working.

    Why won't the page redirect to the correct homepage?

    Thanks for any help

    Daniel

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't believe you need the eval(). Try this:
    home = "http://www.myserver.co.uk/" + home + ".asp";
    Or better yet try this:
    window.location = "http://www.myserver.co.uk/" + home + ".asp";
    Last edited by requestcode; Sep 11, 2002 at 09:29.

  3. #3
    SitePoint Member ScoobyDan's Avatar
    Join Date
    Sep 2002
    Location
    Sussex, England
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Cheers requestcode, that's sorted it . I think I had got to the state that I couldn't see the wood for the trees!

    Thanks again


Bookmarks

Posting Permissions

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