Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

history.back(); doesn't trigger $(document).ready();

I have a webpage that use $(document).ready() to build the interface. Then the user can go to a child page, and to go back to the original page he can press the browser's "previous" button or a "Return" button in the page which triggers a history.back();. Back on the original page, $(document).ready() is not triggered so the page is missing information.

Is there a way to trigger it automatically like if it was a "real load"?

edit

placing an alert in it, the alert is popped but stuff is missing in my interface like if some part of the ready event is missing. Investigating...

edit 2

hahahahaha in document.ready I click some checkbox which are supposed to be unchecked. When I "back" on this page, they are checked so they become unchecked because I reclick them.

Sorry, this is completely my bad :(

like image 912
Sirber Avatar asked Sep 02 '10 15:09

Sirber


3 Answers

A quick solution to this problem, use "onpageshow" instead.

window.onpageshow = function(event) {
    //do something
};
like image 82
stonyau Avatar answered Nov 19 '22 12:11

stonyau


If the user uses the Back button to navigate and you require a full reload of the page, you can set the NO-CACHE policy of the page.

This way the browser is forced to reload the page from the server, even using the Back button.

like image 28
Paulo Santos Avatar answered Nov 19 '22 12:11

Paulo Santos


1.) put scripts at the bottom of your page.
2.) execute plugins and whatnot in your last script tag(s).
3.) Do not use onDomReady implementations at all, it's redundant.

People are so accustomed to onload or ondomready, they overlook the fact that putting your scripts at the bottom of a page does virtually the same thing without the need to poll and see if your html is available.

Furthermore, it's also good practise as your scripts do not block html/css rendering either.

Not depending on onDomReady or onLoad implementations solves a lot of issues.

like image 4
BGerrissen Avatar answered Nov 19 '22 11:11

BGerrissen