By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,886 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

When was the page loaded?

P: n/a
Is there a way for a bookmarklet to know, when exactly the page was loaded
or refreshed? If yes, how? :)
Aug 4 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
optimistx wrote:
Is there a way for a bookmarklet to know, when exactly the page was loaded
or refreshed?
Unlikely.
PoinetdEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Aug 4 '08 #2

P: n/a
optimistx wrote:
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,

--
Bart
Aug 4 '08 #3

P: n/a
On Aug 4, 10:42*am, Bart Van der Donck <b...@nijlen.comwrote:
optimistx wrote:
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,

--
*Bart
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.
Aug 4 '08 #4

P: n/a
On Aug 4, 5:10 pm, Tom Cole wrote:
On Aug 4, 10:42 am, Bart Van der Donck wrote:
>optimistx wrote:
>>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, ...
<snip>
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.
Aug 4 '08 #5

P: n/a
Henry wrote:
On Aug 4, 5:10 pm, Tom Cole wrote:
>On Aug 4, 10:42 am, Bart Van der Donck wrote:
>>optimistx wrote:
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, ...
<snip>
>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.
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.
Aug 4 '08 #6

P: n/a
Tom Cole wrote:
On Aug 4, 10:42*am, Bart Van der Donck <b...@nijlen.comwrote:
>optimistx wrote:
>>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.
[...]

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.

--
Bart
Aug 5 '08 #7

P: n/a
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?
Aug 6 '08 #8

P: n/a
optimistx wrote:
[...]
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>

--
Bart
Aug 7 '08 #9

P: n/a
Bart Van der Donck wrote:
optimistx wrote:
>[...]
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).
Aug 8 '08 #10

P: n/a
optimistx wrote:
Bart Van der Donck wrote:
>*<!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).
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.

--
Bart
Aug 8 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.