Skip to main content

When DID you load that page?

Page rendered on Thu, 04/18/2024 - 8:58pm
(0 seconds ago)

When I'm viewing Drupal administration pages, like referrer logs or other time-sensitive pages, I like to know the time of the last 'refresh' (and therefore how stale the page content is).

So, here's a quick and dirty Drupal block definition. (The javascript is not very idiomatic, but it'll do for now until I can update it. In fact, I plan on making it a pure client-side javascript widget, but that's another post for another day.)

It will display the date and time the page was last loaded, and the 'age' of the page in seconds - it uses a javascript interval timer to update this every second.

In order to use this on your drupal site, create a new block, paste the code into the block content text field, configure it to use the PHP input filter (so the php code can be interpreted by Drupal), position it in the left sidebar area of your theme (you can place it wherever you wish), and set it to be shown only on admin and admin/* pages.


Here's the code:

<div style="float:right; border: red 1px solid;background-color:orange;color:yellow;text-align:center;padding:.5em;">
<?php
// todo: make this all client javascript!
// but, for now, I use the php/Drupal format_date() function to simplify the process of getting a local date/timestamp
$t = time();
echo 'Page generated on ' 
   . format_date(time()) 
   .  '  <span style="color:white;"> <br/%gt;(<span  id="page_render_age">0</span> seconds ago)</span>';
?>
</div>
<script type="text/javascript">
var page_render_time=new Date().getTime();

function page_render_format_interval(now,start)
{
   return parseInt((now - start)/1000);
}
function page_render_update()
{
  var now = new Date();
  var et = page_render_format_interval(now.getTime(), page_render_time);
  var elem = document.getElementById('page_render_age');
  if (elem && elem.textContent) elem.textContent = et; // ff/mozilla
  if (elem && elem.innerText) elem.innerText = et; // ie compatibility
}
window.setInterval("page_render_update()", 1000);

</script>


Disclaimer

*NOTE: All information contained herein is provided for educational purposes only. Exodus Development, Inc. disclaims all liability for use or misuse of the information presented herein or on external web sites. Use your own good judgement, ask an expert first. Proceed at your own risk.