When was the page loaded?

O

optimistx

Is there a way for a bookmarklet to know, when exactly the page was loaded
or refreshed? If yes, how? :)
 
B

Bart Van der Donck

optimistx said:
Is there a way for a bookmarklet to know, when exactly the page was loaded
or refreshed? If yes, how?

It should be no problem to show when the page was first loaded. Just
store a cookie at the first visit of the user with the date in it, and
then read it out at every next visit. The problem here is the refresh.
Perhaps better is a server-side solution (eg. PHP), let it generate
the date, put it in a js variable, and show that variable in the
bookmarklet. This way the refresh should also be included.

Hope this helps,
 
T

Tom Cole

It should be no problem to show when the page was first loaded. Just
store a cookie at the first visit of the user with the date in it, and
then read it out at every next visit. The problem here is the refresh.
Perhaps better is a server-side solution (eg. PHP), let it generate
the date, put it in a js variable, and show that variable in the
bookmarklet. This way the refresh should also be included.

Hope this helps,

Or keep two cookies. The first (first loaded) only gets updated if it
doesn't exist...the second (last refresh) gets updated on each load
whether it exists or not.
 
H

Henry

Or keep two cookies. The first (first loaded) only gets
updated if it doesn't exist...the second (last refresh) gets
updated on each load whether it exists or not.

It would be unusual for a script triggered with a bookmarklet to have
the opportunity to influence the load events of the pages upon which
it operated, and no chance of employing server-side technology.
 
O

optimistx

Henry said:
It would be unusual for a script triggered with a bookmarklet to have
the opportunity to influence the load events of the pages upon which
it operated, and no chance of employing server-side technology.

Thanks for the ideas.
If the bookmarklet creates cookies in the client machine, and reads them
next
time the page is loaded from the server , the bookmarklet gets the cookies
at least several seconds after the the page has been loaded (after the
person has hit the bookmarklet button or menu). The bookmarklet has no
control of the server side (in this case). The cookie created by the
bookmarklet cannot contain the time when the server has sent it or the
client received (?).
Http-response headers might have the page creation time, but can the
bookmarklet read them?
I do not expect the bookmarklet to 'influence' the loading , but it would be
nice to know how much time the client has been studying the page before
activating the bookmarklet. This is not a very important question, but 'nice
to know' - type of thing.
 
B

Bart Van der Donck

Tom said:
It should be no problem to show when the page was first loaded. Just
store a cookie at the first visit of the user with the date in it, and
then read it out at every next visit. The problem here is the refresh.
[...]

Or keep two cookies. The first (first loaded) only gets updated if it
doesn't exist...the second (last refresh) gets updated on each load
whether it exists or not.

The second cookie would indeed indicate the last page view ("load"),
but that is not necessarily a refresh.
 
O

optimistx

Bart Van der Donck wrote:
....
The second cookie would indeed indicate the last page view ("load"),
but that is not necessarily a refresh.

I do not understand this yet. My problem is, whether the client has been
looking at the page some seconds or some minutes before hitting the
bookmarklet.
How would the 2-cookie idea solve this exactly?
 
B

Bart Van der Donck

optimistx said:
[...]
I do not understand this yet. My problem is, whether the client has been
looking at the page some seconds or some minutes before hitting the
bookmarklet.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<title>Bookmarklet</title>
<script type="text/javascript">
var s = 0;
function addsec() {
++s;
setTimeout('addsec()', 1000);
}
</script>
</head>
<body onLoad="addsec();">
<p><a href="javascript:alert(s + ' seconds')">Bookmarklet</a></p>
</body>
</html>
 
O

optimistx

Bart said:
optimistx said:
[...]
I do not understand this yet. My problem is, whether the client has
been looking at the page some seconds or some minutes before hitting
the bookmarklet.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<title>Bookmarklet</title>
<script type="text/javascript">
var s = 0;
function addsec() {
++s;
setTimeout('addsec()', 1000);
}
</script>
</head>
<body onLoad="addsec();">
<p><a href="javascript:alert(s + ' seconds')">Bookmarklet</a></p>
</body>
</html>
Thanks for the example. However, the bookmarklet code is inserted to a page,
which can have come from any domain, and thus the onLoad event is not useful
for the bookmarklet ( the event might have happened minutes earlier).
 
B

Bart Van der Donck

optimistx said:
Thanks for the example. However, the bookmarklet code is inserted to a page,
which can have come from any domain, and thus the onLoad event is not useful
for the bookmarklet (the event might have happened minutes earlier).

If you want a sheer javascript solution, I think you need javascript
code outside of the bookmarklet anyhow, because one way or another,
the start time must be initialized. And that is something a
bookmarklet can't do. That start time doesn't need to be in an onLoad-
event Per Se, although that would be the recommended way.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Bookmarklet</title>
<script type="text/javascript">
var e = (new Date()).getTime();
</script>
</head>
<body>
<a href="javascript:alert(((new Date()).getTime()-e)/1000+' sec')">
Bookmarklet
</a>
</body>
</html>

The start time could also be initialized by server (php, asp, perl,
ssi, ...). In that case, no javascript code outside the bookmarklet is
needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,814
Members
47,360
Latest member
kathdev

Latest Threads

Top