Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go back to previous page without refreshing using jquery, not angularjs

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.

like image 602
Learn AspNet Avatar asked Nov 09 '22 08:11

Learn AspNet


1 Answers

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.

like image 148
Stephen P Avatar answered Nov 14 '22 22:11

Stephen P