Can you use hash navigation without affecting the story?

I’m afraid that this is possibly impossible , but is there a way to change the hash value of the URL without leaving entries in the browser history and without rebooting ? Or the equivalent?

As for the features, I was developing a basic hash of string navigation:

//hash nav -- works with js-tabs var getHash = window.location.hash; var hashPref = "tab-"; function useHash(newHash) { //set js-tab according to hash newHash = newHash.replace('#'+hashPref, ''); $("#tabs li a[href='"+ newHash +"']").click(); } function setHash(newHash) { //set hash according to js-tab window.location.hash = hashPref + newHash; //THIS IS WHERE I would like to REPLACE the location.hash //without a history entry } // ... a lot of irrelavent tabs js and then.... //make tabs work $("#tabs.js-tabs a").live("click", function() { var showMe = $(this).attr("href"); $(showMe).show(); setHash(showMe); return false; }); //hash nav on ready .. if hash exists, execute if ( getHash ){ useHash(getHash); } 

Using jQuery is obvious. The idea is that in this particular case: 1) force the user to return to each permutation of the tabs, can effectively “break the back button”, piling up unnecessary links and 2) not preserving the tab in which they are now if they fall into update annoyance.

+76
javascript jquery browser-history fragment-identifier browser-state
Feb 21 '10 at 6:29
source share
5 answers

location.replace("#hash_value_here"); worked fine for me until I discovered that it wasn’t working on iOS Chrome. In this case, use:

 history.replaceState(undefined, undefined, "#hash_value") 

history.replaceState () works exactly the same as history.pushState (), except that replaceState () changes the current history record instead of creating a new one.

Remember to save # , or the last part of the URL will be changed.

+53
May 29 '14 at 2:39
source share
 location.replace("#hash_value_here"); 

The above seems to do what you need.

+88
Aug 04 '11 at 17:08
source share

Edit: It's been a couple of years now and browsers have evolved.

@Luxiyalu answer is the way to go

- Old answer -

I also think that this is not possible (at this time). But why do you need to change the hash value if you are not going to use it?

I consider the main reason that we use a hash value, as programmers should allow the user to add bookmarks to our pages or save state in the browser history. If you do not want to do this, just save the state in a variable and from there from there.

I think the reason for using a hash is to work with a value that is not under control. If you don’t need it, it means that you have everything under your control, so just save the state in a variable and work with it. (I like to repeat myself)

Hope this helps you. Maybe there is an easier solution to your problem.

UPDATE: How about this:

  • Install the first hash and make sure it is saved in your browser history.
  • When a new tab is selected, do window.history.back(1) , which will return the history from your first initialization hash.
  • Now you set a new hash, so the tab will only make one entry in the history.

You may have to use some flags to find out if the current record can be deleted by returning or just skip the first step. And to make sure your loading method for the "hash" is not executed when you click history.back .

+5
Feb 21 '10 at 7:41
source share

You can always create an event listener to catch events of a click on a hyperlink, and put e.preventDefault () in the callback function, which should prevent the browser from inserting it into the history.

0
Jun 13 '13 at 15:01
source share
 history.replaceState(undefined, undefined, "#profileInfo") 

Where #profileInfo is your identifier.

0
04 Feb '16 at 10:00
source share



All Articles