How to get destination URL with jQuery?

My webpage has a countdown snippet that reads the remaining time from a hidden field. It counts from 300 to 0 in increments of 1 second and therefore updates the hidden field. When I reload the page, the browser maintains the old value of the hidden field, rather than retrieving it from the server.

Excerpt:

<span id = "counter"> & span; </span> <input type = "hidden" id = "remaining" value = "300" />

I need to get the destination URL of the page in the event listener block, for example:

$ (window) .unload (function () {
alerts (window.location.destination);});

Of course, I made up the "destination." I really need to detect a reload and attach a hash parameter to the url to prevent caching.

+3
source share
1 answer

You cannot get the URL of the page that the user will use in the function unload, or in general (in some cases this will be a privacy risk). And the fragment identifier (hash) at the URL will not interfere with caching; changing it will not even reload the page. For caching, you will need to write the part of the ?queryURL that you can do, for example. location.search= '?'+Math.random();.

. , / , , . script DOM:

<span id="counter" class="remaining-300"></span>

, span .className script, JS:

<span id="counter"></span>
<script type="text/javascript">
    var remaining= 300;
</script>

reset 300 .

"bfcache", , script - , , "".

, , , , , . , , - - , . , , , , bfcache , onunload , , .

+2

Source: https://habr.com/ru/post/1744244/


All Articles