Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use the event : </p> <blockquote> <p>onbeforeunload</p> </blockquote> <p>To detect when your user leave your page. Then, send an ajax request. To handle your request, you simply want to save whatever information in a $_SESSION variable in posted.php. </p> <pre><code>// posted.php session_start(); if ( isset ( $_POST['hours'] &amp;&amp; isset ( $_POST['minutes'] &amp;&amp; isset ( $_POST['seconds'] &amp;&amp; ) { $_SESSION['hours'] = $_POST['hours']; $_SESSION['minutes'] = $_POST['minutes']; $_SESSION['seconds'] = $_POST['seconds']; } </code></pre> <p>Then when your new page load / refresh you should have in your javascript your variable that are initialized.</p> <pre><code>var hours = &lt;?php if ( isset($_SESSION['hours']) ) echo $_SESSION['hours'] else 0; ?&gt;; var minutes = &lt;?php if ( isset($_SESSION['minutes']) ) echo $_SESSION['minutes'] else 0; ?&gt;; var seconds = &lt;?php if ( isset($_SESSION['seconds ']) ) echo $_SESSION['seconds '] else 0; ?&gt;; </code></pre> <p>Now understand that this is a shot in the dark since I have 0 idea about the way your application is built. If you're using some kind of framework it might not be that easy but if you're programming something small or procedural, then this will fit your needs.</p> <p>EDIT: I understand that you have multiple timer, instead of using </p> <pre><code>$_SESSION['hours'] </code></pre> <p>use </p> <pre><code>$_SESSION['idOfTimer']['hours'] </code></pre> <p>Each timer will have his own timer. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload