Execute document.ready, even if the user came to the page by clicking the "Back" button

I have a PHP page with jQuery $(document).ready() that makes some changes to the form on the page. It works great. But if I come to this page and then go to another and then remove the "Back" from the browser and return to this page, the $(document).ready() function does not seem to start at all. This happens in both FF and Chrome.

Is it possible to somehow execute document.ready , even if the user clicked the back button of the browser to go to my page?

+7
source share
2 answers

I had exactly the same problem; The @Alfabravo link helped me a lot: stack overflow

The code below worked well for me, since I really needed to do some cleanup either when the user entered the page, or when the page was reached using the back button:

 $(window).on('pageshow', function(){ console.info('Entered the page!'); }); 

If you need to specifically determine when the page was reached using the "Back" button, but not the first time you enter it, you may need to control a bit of state; link can help you.

0
source

You can try this step.

First add a hidden field.

<input id="reload" type="hidden" name="reload" value="" />

Second add javascript code.

 <script type="text/javascript"> $(document).ready(function() { var d = new Date(); d = d.getTime(); if ($('#reload').val().length == 0) { $('#reload').val(d); $('body').show(); } else { $('#reload').val(''); location.reload(); } }); 

-one
source

All Articles