Responsive-Tabs icon indicating copy to clipboard operation
Responsive-Tabs copied to clipboard

Navigation through browser history by hash not working

Open herrschuessler opened this issue 9 years ago • 4 comments

Setting the option setHash to true adds a unique URL hash each time a tab is opened - great feature. Opening a URL with hash via link or typeing in the adress bar opens the corresponding tab - just as expected and advertised.

Navigating through the browser history via the browser's back / forward buttons however does not open the corresponding tabs, instead nothing happens, the last opened tab stays open.

herrschuessler avatar May 18 '15 09:05 herrschuessler

Edit: I see that navigation by browser history is implemented in the _loadEvents function, but it's unreliable in both FF and Chrome / OS X. Sometimes the value _ignoreHashChange (set in line 234) is set to true on the the tabs, preventing them from being opened by navigation through browser history. Howerver, setting _ignoreHashChange seems to fail randomly in the mentioned browsers.

What purpose does _ignoreHashChange serve?

herrschuessler avatar May 20 '15 11:05 herrschuessler

Sorry for the late response. The _ignoreHashChange boolean was built in to prevent an infinite hash change loop. The plugin listens for the hash change event to check if it should activate a tab, but when activating a tab, the hash gets updated. Without the _ignoreHashChange boolean the hashchange event would again be triggered and the tab would again be activated, and so on.

That being said, if this is causing issues with the browser history, it will need to be fixed. I'll try to investigate why this is happening, I don't know when i'll have time though. If you find the problem i'd be happy to accept a PR for the solution :)

jellekralt avatar Aug 06 '15 20:08 jellekralt

Is there anything scheduled in the pipeline for this? This would be a nice to have feature sorted out.

daminloi avatar Apr 07 '16 14:04 daminloi

i actually wanted to provide a fix. in order to understand what caused the infinite hash change loop i commented the line e.data.tab._ignoreHashChange = true;. however, to my surprise, switching between the tabs worked fine and an external link containing a tabref as hash worked also fine. browser history worked accordingly.

tabsContainer.responsiveTabs({
            active: 0,
            load: function(event, firstTab) {
                tabsContainer.css('opacity', '1');
            },
            setHash: true
        });

i tested in

  • IE11
  • Edge 42
  • Chrome Version 74.0.3729.6 (Official Build) dev (64-bit)
  • Firefox 65.0.2 (64-bit)
  • Firefox Developer 73.0b2 (64-bit)

maybe this was an upstream bug?

tomschulze avatar Jan 10 '20 15:01 tomschulze