As others have mentioned, this is not going to be terribly accurate. But this should work reasonably.
In your <head>
, i.e., as early as possible:
<script type="text/javascript">
var startTime = (new Date()).getTime();
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(window).load(function()
{
var endTime = (new Date()).getTime();
var millisecondsLoading = endTime - startTime;
// Put millisecondsLoading in a hidden form field
// or AJAX it back to the server or whatever.
});
</script>
The key is this behavior, from the jQuery docs:
When bound to the window element, the
event fires when the user agent
finishes loading all content within a
document, including window, frames,
objects and images.