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 8201487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:49:53+00:00 2026-06-07T06:49:53+00:00

I need some help with reading cookies. My website is bilingual, and as I

  • 0

I need some help with reading cookies. My website is bilingual, and as I do not want to change language based on IP, I need to be able to set a cookie which I’ll call ‘_lang’ and see if the contents are ‘en’ or ‘jp’. I can set the cookie and its contents, no problems, but I can’t work out the syntax for reading cookie contents; this is the first time I’ve actually tried it.

function createCookie(name,value,days) {
if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

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;
}


function GetCookie(name) {
  var arg=name+"=";
  var alen=arg.length;
  var clen=document.cookie.length;
  var i=0;
  while (i<clen) {
    var j=i+alen;
    if (document.cookie.substring(i,j)==arg)
      return "here";
    i=document.cookie.indexOf(" ",i)+1;
    if (i==0) break;
  }
  return null;
}

var visit=getCookie("_lang");
var rc=readCookie("_lang");
if (visit==true){
        if (rc == "jp"){
            window.location = "http://jp.mywebsite.com";
        }

        else if (rc == "en"){
            window.location = "http://www.mywebsite.com";
        }
}
else if (visit==null){
    document.title = "Welcome to MyWebsite!"
    document.getElementById('welcomeLB').style.display='block';
    document.getElementById('behindLightBox').style.display='block';
}
  • 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-06-07T06:49:55+00:00Added an answer on June 7, 2026 at 6:49 am

    I would recommend to use plugin. https://github.com/pavelkukov/localdata

    in your case:


    var lang_cookie = readCookie('user_lang') ;
    
    if( lang_cookie && lang_cookie !== null && lang_cookie !== 'undefined')
    {
         if(lang_cookie === 'en')
         {
              document.location = 'http://en.mysite.com';
         }
         document.location = 'http://jp.mysite.com';
    }
    
    document.location = 'http://en.mysite.com';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After searching online and reading the Oracle documentation for this, I need some help
I need some help reading data from a text file into my ArrayList .
I need some logic/programming help with reading more than one record from a text
I am reading through http://www.scholarpedia.org/article/SIFT , and I need some help in a definition
I've really hit a wall and am need of some help! Thankyou for reading
I need some help with Mule 3 esb. I am reading a message from
I need some help on something. I am reading some data from an Excel
I need some help with reading an oddly-formatted XML file. Because of the way
I need some help in transforming an input data which is from reading a
I need some help using Linq to xml, I've been reading online articles but

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.