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

  • Home
  • SEARCH
  • 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 7011087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:04:56+00:00 2026-05-27T22:04:56+00:00

lets say that we are studding a url string: http:/domain.com/en/#the-file.html/section-4 where i have codified:

  • 0

lets say that we are studding a url string:

http:/domain.com/en/#the-file.html/section-4

where i have codified:

http:/domain.com/en/#{html file}/{id of the div}-{level}

this way i can know by

var info = window.location.hash;
var temp = info.split("/");
var url = temp[0];
url = str_replace('#','',url);
var temp1 = temp[1];
temp1 = temp1.split('-');
var seccion = temp1[0];
var nivel = temp1[1];

where

console.log('url: '+url);
console.log('info: '+nivel);
console.log('seccion: '+seccion);

provide me those codified vars

the problem is when, for example, the url is

http://domain.com/es/

that firebug jumps this error:

temp1 is undefined

Any idea how to prevent it?

  • 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-27T22:04:57+00:00Added an answer on May 27, 2026 at 10:04 pm

    Instead of using split, I recommend to use a RegExp, which does not break when multiple slashes or hyphens show up.

    The code below will always define the variables url, nivel and seccion. If the hash is not existent, these variables will be an empty string.

    var info = window.location.hash.match(/^#(.*?)\/(.*?)-(.*)$/),
        url="", nivel="", seccion="";
    if (info) {
        url = info[1];
        nivel = info[2];
        seccion = info[3];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say that I have a HTML that looks like this: <div class=aaa><span>1</span></div> <div
Lets say that you have websites www.xyz.com and www.abc.com. Lets say that a user
Lets say that you have either URL or a link on a webpage that
Lets say that I have this code $(document).ready(function() { $(#changeText).click(function() { $(#textBox).html(My<br><br><br>text<br><br><br>is<br><br><br>changed!); }); });
Lets say that I have 10,000 regexes and one string and I want to
Lets say that I purchased a new domain (somedomain.com) from a domain registar and
Lets say that I have this code: <div id=gameFrame> <div id=figure></div> </div> Where the
Lets say that I have a generic collection in the string format. I want
Lets say that I have an array as followed : String[] letter = {a,
Lets say that I have a header user control in a master page, and

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.