For chrome the event fires on page load, but in firefox it fires the rightway, only when you press the backward or forward button. So how to write a script that works fine for all browsers?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’d go browser detection on this one (in fact, I did). I’m using jquery’s .data() to set a boolean flag to test against:
I’ve added this conditional clause in the function that is bound to the popstate event, so the first time it’s called in Chrome (which is on page-load), it just exits the function without doing anything. Next time (prev/back buttons), it will work fine.
I’m stuck with an old version of jQuery on this project, so I couldn’t use jQuery.browser.webkit, but you probably can.