Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  149] [ 4]  / answers: 1 / hits: 20381  / 8 Years ago, fri, september 23, 2016, 12:00:00

I am running a script locally and in one of the functions, it goes to different page. Once it does that, I want it go to back to previous page and continue running the script locally.



Is there a way to go back to previous page without refreshing the page.
I used parent.history.back(); this goes back to previous page but refreshes the page so my script stops running.


More From » jquery

 Answers
3

Is there a way to go back to previous page without refreshing the page?



TL;DR - The short answer is No

    There is no way to go back without refreshing the page.



refresh is a somewhat vague term without an exact technical meaning ...



Going back by any means, whether it's the browser's back button or your .history.back() tells the browser to load the previous page it holds in its history.



Whether the page is loaded from the browser cache or re-requested from the server is up to the browser, not up to you.



In any case, it is again up to the browser whether it will re-parse the DOM and/or re-render the page. Which, in reality, it is going to do.



Any of these could be called refresh.



At that time, however, the browser will start parsing and executing any scripts present. It will not continue wherever it was in the scripts at the time the page unloaded under any circumstances.



The page the browser goes back to is the HTML text as it was received from the server, but scripts could have significantly modified the DOM after the page was loaded. Those scripts need to run again, from the beginning, when the page is reloaded by going back.



It's conceivably possible to write a browser that saves the DOM state and js execution state when you leave a page, and restore that state when you return, but no such browser exists.






Depending on what your actual goals are for this, there are many things that could be done such as pushState() and replaceState(), single-page web applications, XMLHttpRequest, using <iframe>, etc. where you could replace the current page content (DOM) with other content without actually going forward, and restore the saved DOM later when you return to the page,

but that's far too large a topic for a Stackoverflow question.


[#60618] Wednesday, September 21, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raynamadilynl

Total Points: 653
Total Questions: 110
Total Answers: 98

Location: Honduras
Member since Sat, Jul 24, 2021
3 Years ago
;