jQuery .trigger() or $(window) not working in Google Chrome
Posted
by Jonathan
on Stack Overflow
See other posts from Stack Overflow
or by Jonathan
Published on 2010-06-05T13:00:55Z
Indexed on
2010/06/05
13:02 UTC
Read the original article
Hit count: 296
JavaScript
|jQuery
I have this jQuery ajax navigation tabs plugin that I created using some help from CSS-Tricks.com and the jQuery hashchange event plugin (detects hash changes in browsers that don't support it).
The code is little long to post it here but it goes something like this:
Part 1) When a tab is clicked, it gets the href attribute of that tab and add it to the browsers navigation bar like '#tab_name': window.location.hash = $(this).attr("href");
Part 2) When the navigation bar changes (hash change), it gets the href change like this: window.location.hash.substring(1);
(substring is to get only 'tab_name' without the '#'), and then call the ajax function to get the info to display.
I want to automatically trigger the plugin to load the first tab when the page is accessed, so at the start of the code 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 probles is that it works in FF but not in Chrome, I mean, everything works but it seems like the $(window).trigger('hashchange');
is not working because it doesnt get the first tab..
Any suggestions??
© Stack Overflow or respective owner