Hi there,
Script to show on the web page that how many times user loaded it or refresh it. the counter restarted from 0 on closing the browser and open it again.
any help here will be appreciated.
Thanx
Hi there,
Script to show on the web page that how many times user loaded it or refresh it. the counter restarted from 0 on closing the browser and open it again.
any help here will be appreciated.
Thanx
you can do this entirely in the browser without cookies by storing the counter in sessionStorage. It keeps data only for the current tab/session, persists across reloads and form re-posts, and resets to 0 when the tab or browser is closed. That matches your requirement to start over after a browser restart. @stbuchok is also right that a session cookie would work, but if you prefer no cookies, sessionStorage is simpler here. (developer.mozilla.org)
Drop this into your form page. It increments once on every real navigation (initial load, refresh, or submit-redirect back to the form) and shows the count in a read-only textbox. Using pageshow avoids double-counting when users return via the back/forward cache.
<input id="submitCount" type="text" readonly value="0">
<script>
(function () {
var KEY = 'submitCount';
function bump() {
var n = +(sessionStorage.getItem(KEY) || 0) + 1;
sessionStorage.setItem(KEY, n);
var el = document.getElementById('submitCount');
if (el) el.value = n;
}
// Fires on load and reload; skip BFCache restores
window.addEventListener('pageshow', function (e) {
if (e.persisted) return;
bump();
});
})();
</script> Notes:
expires/max-age so it clears on browser close) and render the value anywhere on the page. (developer.mozilla.org)pageshow handler runs on navigations and reloads). (developer.mozilla.org)Jump to Post— Member #905211Please show the code you need help with.
Jump to Post— Member #905211Try using cookies on page load.
Jump to Post— Member #905211So you want the user to know how many times they submitted the form, correct?
If so, again, use cookies.
Please show the code you need help with.
Hi stbuchok,
I am looking for the script. I don't have this one. I search on the net but yet could not find any thing but to refresh pages automatically or manually but to just to count how many times it refresh and the counter shown some where on the page is my requirement.
If you can help me on this. for some good java programmer, i think its easy for him but may be until now, no one ask such thing.
Thanx
Hi Naranga,
if u can help me here too.
Try using cookies on page load.
I don't need cookies. What I need is that,
open a page and there is a text box showing the number 1, after each refresh/submit, this number will go +1 (2,3,4,5,6 ......) so that user know how many times he submit the form (the page is actually a form and on each submit, it redirects to the same webpage (form) so that user can submit the form again).
I hope this clears all.
So you want the user to know how many times they submitted the form, correct?
If so, again, use cookies.
So you want the user to know how many times they submitted the form, correct?
If so, again, use cookies.
No i dont wana know how many times thay submitted the form, the one submitting must know by seeing on the form itself, so that like after 20 or 30 submit he will stop. This is for the user only, for the one who is submitting the form
Yeah, that's what I said "So you want the USER to know how many times THEY submitted the form, correct?"
And yet again, USE COOKIES. Please, just read up on how to use cookies. Cookies can hold the information and it is a user by user basis stored on the client machine. Please, just read up on it.
Yeah, that's what I said "So you want the USER to know how many times THEY submitted the form, correct?"
And yet again, USE COOKIES. Please, just read up on how to use cookies. Cookies can hold the information and it is a user by user basis stored on the client machine. Please, just read up on it.
Ok i will read it up.
but I need that to be appear anywhere on the form page too. Will cookie stuff can do that too. Also I am not very good at these stuff.
Cookies are containers that you can store things about the client into them and retrieve from them. It is done on a per user basis so that the information pertain only to that user. Because you are able to retrieve the data, you are able to display it where ever your heart desires.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.