Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6761351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:10:41+00:00 2026-05-26T14:10:41+00:00

I have an index site which checks if a cookie exists and if it

  • 0

I have an index site which checks if a cookie exists and if it has the value EN. If so it should redirect to an English index.shtml. Otherwise or if there is no (English) cookie, it should redirect to the German next page:

if (document.cookie)  {
    var cookieValue = document.cookie;
    if (cookieValue.indexOf("MYCOOKIE=EN") > -1)  {
        window.location.href="en/index.shtml";
    }
}
window.location.href="kategorien/hauptkategorie.shtml";

Now something very strange happens: The English cookie exists (I checked cookieValue with JavaScript alert and it shows EN), but even though the href inside the if won’t be executed but the 2nd href will be executed. Why is this so?

When I add 2 elses, it works like expected:

if (document.cookie)  {
     var cookieValue = document.cookie;
     if (cookieValue.indexOf("MYCOOKIE=EN") > -1)  {
         window.location.href="en/index.shtml";
     }
     else  {
         window.location.href="kategorien/hauptkategorie.shtml";
     }
}
else  {
     window.location.href="kategorien/hauptkategorie.shtml";
}

Why is this so that it redirects to hauptkategorie.shtml if I leave the elses?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:10:41+00:00Added an answer on May 26, 2026 at 2:10 pm

    You have a normal Javascript statement after the if.

    There is nothing telling that statement not to run, unless you put it in an else.

    Navigating to a new page does not terminate execution of the current page until the new page actually loads.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site which has only ONE file: index.html . I just want
I have already a site with a single homepage index.php which accepts 2 parameters
Information: I have a site that has a design on index.php, and then you
Hey there, I'm trying to make a site which have following: News, Products, About
I have an ecommerce site which currently has product URLs like this: http://www.mydomain.com/nike-tshirt/Large http://www.mydomain.com/nike-tshirt/Medium
I have sample site: /index.html /appcache.manifest /style.css /test.js index.html: <!DOCTYPE HTML> <html manifest=appcache.manifest> <head>
I have my site broken down into several folders by language: / /en/ index.php
I have a url on my joomla site http://www.mysite.com/index.php?option=com_content&view=frontpage&Itemid=3220 My Customer wants it to
i am using php 5.2.8 i have index.html, which loads LOAD.PHP from IFRAME. iframe
I have a php-site with a form on which i output preselected values via

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.