O
optimistx
Is there a way for a bookmarklet to know, when exactly the page was loaded
or refreshed? If yes, how?
or refreshed? If yes, how?
optimistx said:Is there a way for a bookmarklet to know, when exactly the page was loaded
or refreshed?
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,
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.
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.
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.
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.
Thanks for the example. However, the bookmarklet code is inserted to a page,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>
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).
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.