What happens when a webpage is closed? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
1) What happens in the background when a webpage is closed?
2) How can I make the webserver think the page is still being viewed so my script may run?
I would post some code but I don't know where to start, looking for some terms and suggested methods to pursue, not necessarily code examples.
Example:
Let's say I have a javascript that needs to run for a certain amount of time once the user visits the page, but the user closes the page before it completes.
How can I (fake) the connection as being alive (even though the user left) until the script completes?

What happens in the background when a webpage is closed?
unload event is triggered and handled, script execution gets stopped, all webworkers get killed, everything gets cleaned up from memory, etc.
How can I make the webserver think the page is still being viewed so my script may run?
What however is possible to start an ajax request in your page which doesn't get killed by the server when the client aborts the request. In php for example you should take a look for that at ignore_user_abort().

You could try to warn user before leaving the page, and tell him that some work still needs to be done - but nothing more than that, the user will still be able to close the window/tab and your script will abort.
To warn the user, try this:
window.onbeforeunload = function() {
return 'Just give me a minute, please';
};

Related

Detecting if the person viewing the website is the developer [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have a view counter on my website that plots the time spent by a viewer on the site to a Thingspeak chart. I want it to not count my views. So it should detect me. I could maybe change the value of a boolean in Console but that isnt feasible. I thought about storing a cookie on my computer and the website would read it to see if it's me but then its crossite samesite stuff I don't understand. Then I thought about checking if the viewer's IP address is mine. Apparently you need server-side stuff for that and GitHub doesn't allow that. Any more ideas?
A really simple hacky solution without using IP checking / backend logic would be to set a localStorage value to something that shouldn't exist normally. With the site loaded, open your browser console and assign something, eg
localStorage.userIsIshanGoel = 'yes';
Then, in the script on your page, just check that property before running the code that increments the view count:
if (localStorage.userIsIshanGoel !== 'yes') {
incrementViewCount();
}
It's not foolproof - for example, someone could examine the source code of the page and set the property themselves, but if the view count is just for your personal informational use, that's quite unlikely to happen (and even then, that's only a single user).

Where are websites html/js stored on local computer, in chrome, windows 10? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
When typing some url, e.g www.google.com (or www.news.com or any other), some client-side code gets downloaded to my local machine, so that the browser can display and run whatever is in there.
I would like to look at that code and maybe slightly modify it.
My google searches failed, probably because I am unfamiliar with the correct terminology for what I am searching. I wasn't even sure about which tags to put on this question.
Where are websites client-side files stored locally? Specifically on chrome, windows 10
If you want to view and edit at the source of the page you're currently looking at, and have your changes reflected in the page immediately, use the browser developer tools (this will be much better than "View source", as it will interpret any clientside DOM generation, give you a collapsible, edited, nested-list view of the DOM, etc).
If you want to make changes that would persist, i.e. every time you view a particular website your changes will be applied to it automatically, then you're looking at building yourself a browser extension, either for your specific browser or cross-browser.
Browsers don't, as far as I know, store the source of a page during render on disk in any way that can be viewed or usefully modified.

Keep timer running even when user logs off [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am trying to build a web app on asp.net core. Here’s what I want to able to do:
where a user can login and click a timer to start.
Even when the user logs of the timer still keeps track of time in real time until someone (the user/ administrator) logs back in to click the end button.
Then I want to be able to capture the start time and end time (in real time) so that I can calculate the difference and store it.
I know I’m probably going to need some Javascript code to have the timer run in the browser but I’m not sure how to keep the timer running even when the user logs off. Any suggestions on how to achieve this?
When user clicks button you send request to the server and save time of the click into the database.
When user opens page, you get start time from the DB and start counting from it.
When user clicks stop button, you send request to the server and save the etop time.
Of course you have to use it's own id for each timer.

Is it possible to make a web-app which works offline? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I know I could utilize client-side storage, cookies, WebSQL to make an app independent of the internet if the tablet/phone went offline for a bit. But at the end of the day if the user refreshes the browser, the site will try to load the HTML/CSS/JS and it's going to fail to load. I haven't been keeping up on HTML5 enhancements in the last year so I'm wondering if something like this exists. For instance specifically telling the browser to cache the static assets and use them again upon reload unless newer versions exist.
NOTE: I'm only interested in how to allow the page to go through a reload with the site offline if such thing exists.
I believe that #NickZuber has answer my question with his link. The thing I was looking for is
Application Cache
Works on most (90%+) modern browsers Best suited for storing
application code
The only option to reliably load a website from nothing offline
Can storage a significant amount of data (50mb+)
Very difficult use without causing unintended consequences for most
websites
Here is a working example of it in action. You can essentially turn off your internet, hit refresh on the browser, close the browser and re-open it. Whatever you want and the app loads up just fine complete with Images, CSS Styles, and Javascript.

What can I do to create an always-live HTML page? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have been searching across the Web to find a solution to this:
Basically what I want to setup is a way to have an HTML page on a live production site to kept updated. This is because I have setup a SilverStripe Application as part of a graphics system (green chroma key) that runs through normal HTML.
AJAX load doesn't seem to be an option here since the load would be every 1 second or half a second to make sure the page is live.
I looked into web socket quite vaguely but the whole concept of integrating it with my project confused me entirely.
Anyone got any ideas of what could be done?
To do this you'll need a combination of:
AJAX, you'll need to never do a full page load after the initial Web 1.0 request.
Session history management, you'll need this in order to not break the browser navigation (e.g. back/forward buttons).
Web Sockets, you'll need this so when new content arrives on the server it is received by the client without first having to poll the server.
Web sockets will be the greatest challenge. I listed them in the order in which you should approach the project, in three phases.

Categories

Resources