1

I am using History.js to make my ajax pages bookmarkable and to have the expected back/forward browser button experience. In Safari all works great but in Firefox 6 if I leave my site and then go back using hte back button I get the javascript instead of the page:

  1. go to mysite.com/user/1/post_board
  2. click on post filter, address changes to mysite.com/user/1/post_board?filter=one
  3. enter google.com in address bar
  4. push the back button
  5. I see the javascript loaded at step 2

What is going? What I am doing wrong?

Here is the code:

// Bind to StateChange Event History.Adapter.bind(window,'statechange',function(e) { var state = History.getState(); eval(state.data.function_rest + "("+JSON.stringify(state)+");"); History.log(state); }); $('.message_filter').bind('click', function() { History.pushState({"function_rest":"restore_post_board_widget"}, document.title, this.href); return false }); function restore_post_board_widget(state) { $.getScript(state.url); } 

Thanks for any help.

3
  • Not another use of eval. :/ Commented Sep 11, 2011 at 7:34
  • Does the url mysite.com/user/1/post_board?filter=one always return HTML? Or does it sometimes return JavaScript? Commented Sep 11, 2011 at 13:45
  • @Shef: I am open to suggestion on how to handle the history management. Using eval allows quite a bit of flexibility but again I am a total newbie to Javascript: stackoverflow.com/questions/7340906/… Commented Sep 11, 2011 at 16:21

1 Answer 1

2

just add:

window.onunload = function(){};

this is where I got the answer:

After travelling back in Firefox history, JavaScript won't run

Sign up to request clarification or add additional context in comments.

2 Comments

That's the worst solution to your problem, it degrades browser performance. See stackoverflow.com/questions/7194095/… for the other options.
Thanks for pointing that out but even after reading the question you pointed to I do not see any other alternative. Can you point me in the right direction? Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.