Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload page without disrupting currently running Javascript

Is there any way to reload a page without resetting Javascript code that is currently running on the page (for example, being run via the Chrome dev console)?

My situation is that I have a page that I need to keep reloading and running code on automatically. However, whenever I refresh the page using window.location.reload( ) it stops any Javascript that I'm currently running on the page.

Is there any way that I can keep refreshing the page but keep running the same code?

like image 882
Avery Avatar asked Jan 26 '26 21:01

Avery


1 Answers

Thanks to dandavis for this answer.

By using ajax, I was able to select a div that encompassed the page and selectively reload it. Effectively, this means that the contect of the page was refreshed.

The code looks something like this:

$('#mydiv').load(document.URL +  ' #mydiv');

Example (where middle is the ID of the div):

$('#middle').load(document.URL +  ' #middle');
like image 90
Avery Avatar answered Jan 28 '26 10:01

Avery