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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:50:29+00:00 2026-05-18T11:50:29+00:00

is it possible to change the location url without the browser refreshing the page

  • 0

is it possible to change the location url without the browser refreshing the page ?

imagine I want the user to change some values on some fields and as a consequence of this
to update is url (following the question mark)

so http://www.mysite.com/mypage?level=1&fav_fruit=apple&fav_food=pasta&…

the idea is that if it changes the ‘favourite food’ i might change the url only

http://www.mysite.com/mypage?level=1&fav_fruit=apple&fav_food=rice&…

but I don’t want to refresh the page.

why ? so he/she can continue to use the page and when he/she is tired he can bookmark it the way it left it (given a good name to it)

any idea ?

I will do this with javascript.

  • 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-18T11:50:30+00:00Added an answer on May 18, 2026 at 11:50 am

    It’s not possible to update the part after the question mark without refreshing the page, but you can update the URL hash (so it looks like http://domain.com/file.php#fav_fruit=apple). I don’t know how to do it in plain old JavaScript but I have done this using jQuery and the jQuery.address plugin.

    You can then set the textbox to update the URL every time the value is changed by doing something like the following:

    $("#mytextbox").change(function(){
      $.address.parameter("fav_fruit", $(this).value());
    });
    

    The good thing with this plugin is that you can attach a function so that you can detect when the URL is changed (i.e. when the bookmark is reloaded):

    $.address.externalChange(function(){
       var favFruit = $.address.parameter("fav_fruit");
       // Set any textboxes, values, etc
    });
    

    By default, the plugin will create a history action everytime a value is update (so you can press back/forward). You wouldn’t want this so you’d have to have this before you set any values:

    $.address.history(false);
    

    Update: Here’s what it looks like in plain old JavaScript:

    // Stores name/value pairs that have changed
    var updatedValues = [];
    
    // Updates or adds an element to 'updatedValues'
    function change(obj) {
        updatedValues[obj.name] = obj.value;
        setHash();
    }
    
    // Gets all the changes variables/values and sets the hash
    function setHash() {
        var arr = [];
        for (x in updatedValues) {
            arr.push(x + '=' + escape(updatedValues[x]));
        }
        location.hash = arr.join('&');
    }
    
    // Returns an object to return the values from the hash string
    function readHash() {
        var locationHashParts = location.hash.substr(1).split('&');
        var params = {};
    
        for (paramName in locationHashParts) {
            var keypair = locationHashParts[paramName].split('=');
            params[keypair[0]] = unescape(keypair[1]);
        }
    
        return params;
    }
    

    It’s not pretty, but it works. change is what you set your form elements to call and it will set the URL hash with the required bits. When you want to set the values in the form fields (for example, when you load the page), you call the readHash to get an object with all the parameters/values in the location.hash field.

    Example of it working at http://jsfiddle.net/ENHFN/ (although you can’t see the location hash change, it uses the variable). I kept getting errors when I tried to separate it out.

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

Sidebar

Related Questions

I know it's possible to change some columns in GridView controls to check boxes
Is there a way I can modify the URL of the current page without
Possible Duplicate: How to rewrite URL without refresh, like GitHub.com Hi all, I have
I change the bookmark in the url when the page is loaded. That way,
Still now I knew Its not Possible to change the contents of location bar
is it possible to have <a href=index.php > click </a> that doesn't change page
Possible Duplicate: Change CSS Dynamically I need to change the height of a div
Is it possible to change the width of a scroll bar on a form.
Is it possible to change the font size used in a ContextMenu using the
Is it possible to change a Sharepoint 2007 Site Theme through a Web Service?

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.