When the user clicks the back button, then document.ready
will not fire. This is the heart of the issue you are facing. One way would be to place your scripts at the bottom of the page and not in an onload method to ensure that they always execute.
Another way would be to take the approach of this StackOverflow answer: https://stackoverflow.com/a/170478/1026459
If you set history.navigationMode to 'compatible' then jQuery's ready function will fire on Back button operations
history.navigationMode = 'compatible';
$(document).ready( function(){ /* code */ });