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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:26:26+00:00 2026-06-14T22:26:26+00:00

I have one html page, index.html for language selection (simple black overlay with 2

  • 0

I have one html page, index.html for language selection (simple black overlay with 2 language links), which acts as the page user always goes to unless adding /EN or /CN to the address, then each link links to a different html file, EN.html and CN.html.
Does anyone know how to create a cookie so that the first time someone visits my site, s/he’ll go normally to the language selection index.html, select the language, create a cookie to remember the selection, then in subsequent visits completely skip index.html and go straight to either http://www.mywebsite.com/EN or http://www.mywebsite.com/CN, even if s/he types in “www.mywebsite.com”?
I read a tutorial on this site in creating a cookie that remembers language selection, which basically boils down to the JQuery cookie plugin, and a script like this:

$(function () {

var url = 'your_url';
var en_page = 'en.html';
var cn_page = 'cn.html';

if ($.cookie('default_page') != null) {
    if (window.location.href != url + '/' + $.cookie('default_page')) {
        window.location.href = url + '/' + $.cookie('default_page');
    }
}

$('#set_en_button').click(function () {
    $.cookie('default_page', en_page, { expires: 999 });
});

$('#set_cn_button').click(function () {
    $.cookie('default_page', cn_page, { expires: 999 });
});

});

But I think this only works if the language selection page is the same html file as one of the languages? What the language selection page is a separate page?
Thanks.

  • 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-14T22:26:27+00:00Added an answer on June 14, 2026 at 10:26 pm

    You can go about this problem in two ways. The more reliable, but more complicated way is to clear the cookie whenever you click a link to navigate back to the homepage. Example:

    <a href="index.html" class="return-link">Back Home</a>
    <script type="text/javascript">
    $(function() {
        $('.return-link').click(function(e) {
            $.removeCookie('default_page');
        });
    });
    </script>
    

    This solution is not ideal because:

    • it’s hard to maintain as you add more links back to your homepage throughout your site

    The more elegant solution is to just alter your homepage code and use the document.referrer property. This property holds the last page visited prior to arriving on the current page. Using this knowledge, you can alter your code to read:

    $(function () {
    
    var url = 'your_url';
    var en_page = 'en.html';
    var cn_page = 'cn.html';
    
    // if the last page you visited has the same hostname
    // as the index page, (eg. www.domain.com == www.domain.com)
    // you must be coming from a page on your own site
    // therefore clear the existing cookie
    if (document.referrer.host == document.location.host) {
        $.removeCookie('default_page');
    }
    
    if ($.cookie('default_page') != null) {
        if (window.location.href != url + '/' + $.cookie('default_page')) {
            window.location.href = url + '/' + $.cookie('default_page');
        }
    }
    
    $('#set_en_button').click(function () {
        $.cookie('default_page', en_page, { expires: 999 });
    });
    
    $('#set_cn_button').click(function () {
        $.cookie('default_page', cn_page, { expires: 999 });
    });
    
    });
    

    This solution is much more scalable because:

    • you don’t have to modify any other files

    Note: the referrer field may sometimes be null under special circumstances. You will have to research how dependable it is, but I think in this case, it should work almost all of the time.

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

Sidebar

Related Questions

In my home page template Index.html.twig I have one navigation bar which i only
In my Rails app, I have a model Page which represents one HTML article
1) We have a page index.html with blocks: <body> <div id=action1>One</div> <div id=action2>Two</div> <div
I have built a Twitter client that's only one page: index.html. When being used,
I have one index.html page and on this page I have three controls; one
i shall state my problem here.. I have an index.html page which has a
I have two html pages one index.html and groups.html each page as ul >
My problem is I have one html table in jsp page .And i applied
In my html page, I have one table, for every row there are two
I have one page website only using HTML, CSS and JavaScript. I want to

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.