0

I am using backbone.js and I want to reload a resource .js file when a user navigates back to a page, e.g. using:

window.history.back();

So not necessarily reloading the page. This is because I need to reset a huge set of global variables and I don't want to make a function that resets 200+ variables and manage both sets when making/removing new variables).

How can I reload the .js file so all my global vars are wiped clean?

And please save the lecture on the evil of global vars ;)

SOUser
  • 610
  • 1
  • 11
  • 25

1 Answers1

0

load the javascript file via an AJAX request.

if you're also using jQuery, the use http://api.jquery.com/jQuery.getScript/

Darryl
  • 1,451
  • 1
  • 12
  • 19
  • thanks for the response Darryl, what if the script is not an external file - it's already loaded in s a script tag – SOUser Dec 11 '13 at 16:36
  • You can setup a fn inside the script to refresh the data. It appears that Firefox won't run scripts onload when the back button is clicked, so you may have to follow the answer on this page. http://stackoverflow.com/questions/2638292/after-travelling-back-in-firefox-history-javascript-wont-run – Darryl Dec 11 '13 at 20:14
  • sorry, i don't see a solution on that page – SOUser Dec 12 '13 at 14:05
  • Just this part to address Firefox. window.onunload = function(){}; – Darryl Dec 12 '13 at 18:08