For work, I spend a lot of time on domain-specific forums. Throughout the day, I check those forums to see if there are any questions and answers relevant to what I am working on. However, the particular site I am using does not automatically update, and so I have to refresh it. This isn't that big of a deal, but I decided I would save the following JavaScript script as a bookmark:
setInterval(function() { document.location.reload(true); }, 1000);
Essentially, I wanted to force the page to reload every second. However, when it reloads it seems it causes my script to stop running, and so the only effect of my script is a single reload. It's no better than just refreshing the site by hand.
I suppose the more general question is "is there any way to keep a script running even when a user travels to a new site?" I'm guessing not, as then sites could track you as you browsed the rest of the internet. Still, it seems that there might be levels of script execution; perhaps executing a script from a bookmark is different than a <script> tag on a webpage; if I were a browser designer I would have taken that into account and treated is as "browser code" running behind the scenes independant of the currently loaded page. Is that the way browsers work, or does it see all scripts as just running on the currently loaded page?
Thanks!