1

I am having a problem with the hashchange event in Firefox. We are using the JQuery hashchange plugin provided by Ben Alman. The code is as follows.

$(window).hashchange(function (e) {
    alert("Hello");
    //we want to perform a post in here.
});
var temp = "#123";
if (temp !== "") {
    if (window.location.hash == temp) {
        $(window).hashchange();
    } 
    else{
        window.location.hash = temp;
    }
} 
else {
    window.location.hash = "#Home/Home";
};

Now this works fine in IE9 and Chrome, however in Firefox, I see the alert, but as soon as I click OK, the page refreshes, displays the alert again, and continues infinitely. Is there some sort of weird behaviour that Firefox uses that I am unaware of? Or is there simply some other problem that is hidden deeper?

Anthony Wood
  • 395
  • 1
  • 3
  • 16

2 Answers2

0

In some browsers window.location.hash includes the # and in some don't so its better if your ignore it while comparing the hash value in your code.

Try this.

$(window).hashchange(function (e) {
    alert("Hello");
    //we want to perform a post in here.
});
//Remove hash from here which will be compared with window.location.hash
var temp = "123";
if (temp !== "") {
    //Replace # by empty nothing
    if (window.location.hash.replace('#', '') == temp) {
        $(window).hashchange();
    } 
    else{
        window.location.hash = '#' + temp;//Now add the hash here
    }
} 
else {
    window.location.hash = "#Home/Home";
};
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
  • Thanks for the tip but this was not the problem. We found the solution to the problem here http://stackoverflow.com/questions/7110023/firefox-6-infinite-page-refresh-with-page-with-hash-tags – Anthony Wood Feb 19 '12 at 22:22
0

We located the problem as occuring in MicrosoftAjax.js and found the following solution: Firefox 6 Infinite Page Refresh With Page With Hash Tags

Community
  • 1
  • 1
Anthony Wood
  • 395
  • 1
  • 3
  • 16