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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:25:46+00:00 2026-05-23T12:25:46+00:00

this is a very beginner question but I don’t know javascript, I only wants

  • 0

this is a very beginner question but I don’t know javascript, I only wants implement a snipplet I found googling around.

The original code is:


var langcodes=["it", "es"];
var langCode = navigator.language || navigator.systemLanguage;
var lang = langCode.toLowerCase(); 
lang = lang.substr(0,2); 
var dest = window.location.href; 
for (i=langcodes.length-1;i >= 0; i--){
    if (lang==langcodes[i]){
        dest = dest.substr(0,dest.lastIndexOf('.')) + '-' + lang.substr(0,2) + dest.substr(dest.lastIndexOf('.'));
        window.location.replace ?window.location.replace(dest) :window.location=dest;
    }
}

if my browser language is it_IT, will replace

    http://www.mysite.com/test.html 

to

    http://www.mysite.com/test-it.html 

i’d like the new url was:

    http://www.mysite.com/it/test.html 

I tried several ways with no luck.

Any help is appreciated.

Max

  • 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-23T12:25:47+00:00Added an answer on May 23, 2026 at 12:25 pm

    Try this…

     dest = dest.substr(0,dest.lastIndexOf('/')) + '/' + lang.substr(0,2) + dest.substr(dest.lastIndexOf('/'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i know this question was asked before but i have this very weird beginner
I know this is a very beginner question, but I'm obviously a beginner. I
I know this question is probably very basic, but I am a beginner so
This is a very beginner question. I have tried to search for advice but
I know this is probably a very beginner question that I just can't seem
Okay, this might be a very silly beginner question, but: I've got an ClassA,
This is a very beginner question, but driving me crazy. Why isn't this code
Ok so this is probably a very beginner question but... Right now I have
This is a very beginner question. But I'm stumped. How do I reference a
I know that my this question may sound pathetic to you but as a

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.