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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:01:50+00:00 2026-05-25T10:01:50+00:00

Consider the following code: hashString = window.location.hash.substring(1); alert(‘Hash String = ‘+hashString); When run with

  • 0

Consider the following code:

hashString = window.location.hash.substring(1);
alert('Hash String = '+hashString);

When run with the following hash:

#car=Town%20%26%20Country

the result in Chrome and Safari will be:

car=Town%20%26%20Country

but in Firefox (Mac AND PC) will be:

car=Town & Country

Because I use the same code to parse query and hash params:

function parseParams(paramString) {

        var params = {};
            var e,
            a = /\+/g,  // Regex for replacing addition symbol with a space
            r = /([^&;=]+)=?([^&;]*)/g,
            d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = paramString;

        while (e = r.exec(q))
           params[d(e[1])] = d(e[2]);

        return params;

    }

Firefox’s idiosyncrasy here breaks it: The car param winds up being “Town”, no country.

Is there a safe way to parse hash params across browsers, or to fix how Firefox reads them?


NOTE: This issue is limited to Firefox’s parsing of HASH params. When running the same test with query strings:

queryString = window.location.search.substring(1);
alert('Query String = '+queryString);

all browsers will show:

car=Town%20%26%20Country

  • 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-25T10:01:51+00:00Added an answer on May 25, 2026 at 10:01 am

    A workaround is to use

    window.location.toString().split('#')[1] // car=Town%20%26%20Country
    

    Instead of

    window.location.hash.substring(1);
    

    May I also suggest a different method (looks simpler to understand IMHO)

    function getHashParams() {
       // Also remove the query string
       var hash = window.location.toString().split(/[#?]/)[1];
       var parts = hash.split(/[=&]/);
       var hashObject = {};
       for (var i = 0; i < parts.length; i+=2) {
         hashObject[decodeURIComponent(parts[i])] = decodeURIComponent(parts[i+1]);
       }
       return hashObject;
    }
    

    Test Case

    url = http://stackoverflow.com/questions/7338373/window-location-hash-issue-in-firefox#car%20type=Town%20%26%20Country&car color=red?qs1=two&qs2=anything

    getHashParams() // returns {"car type": "Town & Country", "car color": "red"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: class Program { static void Main(string[] args) { new Program().Run(args);
Consider the following code snippet private void ProcessFile(string fullPath) { XmlTextReader rdr = new
Consider the following code: class Program { static void Main(string[] args) { A a
This is rather interesting, I think. Consider following code, both the window.onload and body
Consider following code: ArrayList<Integer> aList = new ArrayList<Integer>(); aList.add(2134); aList.add(3423); aList.add(4234); aList.add(343); String tmpString
consider the following code: string x=3F; //0011 1111 string y=3F; //0011 1111 string result=FFF;
Consider following code public class City { public string Name { get { return
Consider the following code, public class StartUp { public StartUp(String[] test){} public static void
Consider the following code snippet below. class X { public String toString() { return
Consider the following code : class TextMessage{ public : TextMessage(){}; TextMessage(std::string _text):text(_text){} std::string text;

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.