When was the page loaded?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • optimistx

    #1

    When was the page loaded?

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


  • Thomas 'PointedEars' Lahn

    #2
    Re: When was the page loaded?

    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

    Comment

    • Bart Van der Donck

      #3
      Re: When was the page loaded?

      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

      Comment

      • Tom Cole

        #4
        Re: When was the page loaded?

        On Aug 4, 10:42 am, Bart Van der Donck <b...@nijlen.co mwrote:
        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.

        Comment

        • Henry

          #5
          Re: When was the page loaded?

          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.

          Comment

          • optimistx

            #6
            Re: When was the page loaded?

            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.


            Comment

            • Bart Van der Donck

              #7
              Re: When was the page loaded?

              Tom Cole wrote:
              On Aug 4, 10:42 am, Bart Van der Donck <b...@nijlen.co mwrote:
              >
              >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

              Comment

              • optimistx

                #8
                Re: When was the page loaded?

                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?


                Comment

                • Bart Van der Donck

                  #9
                  Re: When was the page loaded?

                  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>Bookmark let</title>
                  <script type="text/javascript">
                  var s = 0;
                  function addsec() {
                  ++s;
                  setTimeout('add sec()', 1000);
                  }
                  </script>
                  </head>
                  <body onLoad="addsec( );">
                  <p><a href="javascrip t:alert(s + ' seconds')">Book marklet</a></p>
                  </body>
                  </html>

                  --
                  Bart

                  Comment

                  • optimistx

                    #10
                    Re: When was the page loaded?

                    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>Bookmark let</title>
                    <script type="text/javascript">
                    var s = 0;
                    function addsec() {
                    ++s;
                    setTimeout('add sec()', 1000);
                    }
                    </script>
                    </head>
                    <body onLoad="addsec( );">
                    <p><a href="javascrip t:alert(s + ' seconds')">Book marklet</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).


                    Comment

                    • Bart Van der Donck

                      #11
                      Re: When was the page loaded?

                      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>Bookmark let</title>
                      >  <script type="text/javascript">
                      >     var s = 0;
                      >     function addsec()  {
                      >       ++s;
                      >       setTimeout('add sec()', 1000);
                      >     }
                      >  </script>
                      > </head>
                      > <body onLoad="addsec( );">
                      >  <p><a href="javascrip t:alert(s + ' seconds')">Book marklet</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>Bookmark let</title>
                      <script type="text/javascript">
                      var e = (new Date()).getTime ();
                      </script>
                      </head>
                      <body>
                      <a href="javascrip t: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

                      Comment

                      Working...