run javascript every 24 hours I want to run a piece of javascript every 24 hours for each specific user? This is to clear HTML5 local storage, how would I run this script every 24 hours for each user when they are logged in?
The best way would be to to store an additional value in local storage that is the last time you cleared it.

Each page view, you simply check that value and if the last time was > 24 hours ago, you clear the local storage and set the last clear time to now.

(function () {

  var lastclear = localStorage.getItem('lastclear'),
      time_now  = (new Date()).getTime();

  // .getTime() returns milliseconds so 1000 * 60 * 60 * 24 = 24 days
  if ((time_now - lastclear) &gt; 1000 * 60 * 60 * 24) {

    localStorage.clear();

    localStorage.setItem('lastclear', time_now);
  }

})();


Put this in a JS file that is added only when the current user is logged in.

Here is an example using a module named 'sample':

/**
 * Implements hook_init().
 */
function sample_init() {
  global $user;

  // User with uid 0 is anonymous/logged out, any uid greater is logged in.
  if ($user->uid > 0) {
    drupal_add_js(drupal_get_path('module', 'sample') . '/js/sample.js');
  }
}