JQuery.trigger () or $ (window) does not work in Google Chrome

I have this jQuery ajax navigation tabs plugin that I created with some help from CSS-Tricks.com and the jQuery hashchange event plugin (detects hash changes in browsers that don't support it).

The code does not last long to publish it here, but it looks something like this:

Part 1) When a tab is clicked, it gets the href attribute of that tab and adds it to the browser navigation bar, for example '#tab_name': window.location.hash = $(this).attr("href");

Part 2) When the navigation bar changes (hash change), it receives the href change as follows: window.location.hash.substring(1);(the substring should get only "tab_name" without "#"), and then call the ajax function to get the information to display.

I want to automatically run the plugin to load the first tab when accessing the page, so at the beginning of the code that I put:

if (window.location.hash === '') { // If no '#' is in the browser navigation bar
   window.location.hash = '#tab_1'; // Add #tab_1 to the navigation bar
   $(window).trigger('hashchange'); // Trigger a hashchange so 'Part 2' of the plugin calls the ajax function using the '#tab_1' added
}

The problem is that it works in FF, but not in Chrome, I mean that everything works, but it $(window).trigger('hashchange');doesn't seem to work because it does not get the first tab.

Any suggestions

Note. It worked some time ago, but suddenly it doesn’t happen (maybe a Chrome update).

+5
source share
1 answer

I suspect that you are trying to trigger an event so that the browser is not satisfied. Where is your handler for "hashchange" defined? I suggest you try tying it to

$('body').bind('hashchange', function() { ... })

"". WebKit; , <div>, .

+2

All Articles