Search code examples
jqueryajaxbuttonback

Jquery add variable to back button


I have an AJAX call on a page, that uses some variables from url at page load.

www.myurl.com/?mayvar=foo

These variables can be changed before user goes to next page. For example user checks a checkbox, and I got new variable.

mynewwar=bar

How can I make a back button to lead to a new address

www.myurl.com/?mayvar=foo&mynewwar=bar

if user wants to go back?


Solution

  • Try putting the variables in hash:

    var variable = 'mayvar=foo&mynewvar=bar';
    location.hash = variable;
    

    this will change the url without going out of the page, and the back button will remember
    the past hashes (of course you'll have to change your script accordingly to read from the hash)