Using cookies and JavaScript to create a page to page timer.

I have long wanted to be able to measure the time it takes to get from one page to another.  While reading in my JavaScript reference the other day, I came across cookies.  I've long known about cookies but have never used them.  The thing that looked attractive was that you can access cookies from both JavaScript and CF.
So I put together the procedures to store the "start time" (startTimeP8D) for the transition and activated it on the onUnload event of a 1stpage.  After a few rewrites I got it working.   Here is the JavaScript to do that: it consists of two functions: doTimer which is the input section and setCookie, which writes to the cookie.  Not the two numbered alert statements.
doTimer - results for "start" from the doTimer function called from page 1 when it unloads. (See doTimer below)
     Please note that the two startTime8D values are the same immediately after they are stored.
On the 2nd page in the sequence, I run the corresponding code to determine the "end time", compute the delta and write it out to the page.  It didn't all run on the first try, but it now seems to be running without a crash, which can be misleading.
      second set of outputs from page 2:    
     Please not that while the endTimeP8D match, the startTimeP8D value no longer matches the previously stored value. 
There is one major hitch in the get along which has me stymied:  As you can see, when you compare the startTimeP8 in the setCookie – results above and the "startTimeP8" in the doTimer results below the startTimeP8 is not the value that I wrote to the cookie @ unload of page 1.  I have checked and checked and do now see anywhere that the startTimeP8D value is being overwritten.  Based upon my limited experience with JavaScript cookies, it seems to me that you get an entry for each time you set the cookie.  So I would expect to see to startTimeP8D entry for each setCookie event, not a different value.
     The result of the failed computation is shown on the bottom of the page.  As you can see, the Total Elapsed Time is negative, which is never a good sign.  The other time shown, Page build time, is the run time from the server.  The whole purpose is to be able to show folks that the reason the code might be show is because of their overloaded network and not our code.  We had one client whose had users running on 56k modems.  It was so slow their VPN software was timing out!!!  Still the had the never to blame us!!!
I am using SQLServer 2005, CF8, IE8 on W7. 
I'm not married to this way of doing this so if anyone has a better/easier way of doing a "page to page timer", I'm up for it.  I'd prefer to fix this one since I've been working on it for the past 3 days.
Thanks in advcance for your help.
Len, PHRED SE

Here it is with no JQuery or console logging calls using cookie utility functions found here:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
     <title>Test JavaScript Page Load Timer</title>
     <script>
          window.onload = function(){
               var previousPageUnload = getCookie('unloadTime');
               if(previousPageUnload){
                    var d = new Date();
                    var loadTime = d.getTime() - previousPageUnload;
                    alert(loadTime + 'ms');
          window.onunload = function(){
               var d = new Date();
                 setCookie('unloadTime',d.getTime());
          function setCookie(c_name,value,expiredays) {
               var exdate=new Date();
               exdate.setDate(exdate.getDate()+expiredays);
               document.cookie=c_name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
          function getCookie(c_name) {
               if (document.cookie.length>0) {
                 c_start=document.cookie.indexOf(c_name + "=");
                 if (c_start!=-1)
                   c_start=c_start + c_name.length+1;
                   c_end=document.cookie.indexOf(";",c_start);
                   if (c_end==-1) c_end=document.cookie.length;
                   return unescape(document.cookie.substring(c_start,c_end));
               return null;
     </script>
</head>
<body>
     <h1>Test JavaScript Page Load Timer</h1>
</body>
</html>
Note that overwriting global window events like this is not a good idea, which is why I used JQuery in my earlier example. I strongly suggest you look at JQuery or one of the other JS libraries (YUI, etc.) to help with event handling. I'll leave it at that as this is getting into JavaScript development, not really on topic for a ColdFusion forum.

Similar Messages

  • Remember Login using cookies and javascript

    Hello all,
    This is an urgent request. Pls reply asap.
    I have two jsps one in English and other in french. I need to implement a functionality to remember the username in both these jsps. I have a function written in javascript to check if the "remember me" checkbox is enabled and then remember the user name. But it is not working as expected. It remembers in one jsp and if i go to french jsp all the info is lost.
    Can you pls help me? Sample code would help.
    I guess the cookie works only for the jsps under certain folder path say en/jsp/.. and fr/jsp/..

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Login Form</title>
    </head>
    <body>
    <form name="login" method="post" action="Home.jsp">
    Email : <input type="text" name="email" /><br />
    Password : <input type="password" name="password"/><br />
    <input type="checkbox" name="rememberChk" value="on" />Remember Me <br/>
    <input type="hidden" name="remember" value="0"/>
    <input type="button" value="Sumbit" onClick="submitForm()"/>
    </form>
    </body>
    <script>
         <%
         String email="";
         String password="";
         Cookie cookies [] = request.getCookies ();//Get All Cookies from Client Device
         if (cookies != null){//Check cookies are available
              for (int i = 0; i < cookies.length; i++){
                   if (cookies .getName().equals("password")){
                        password=cookies[i].getValue();//Password which is saved on cookie
                        break;
              for (int i = 0; i < cookies.length; i++){
                   if (cookies [i].getName().equals ("email")){
                        email=cookies[i].getValue();//Email which is saved on cookie
                        break;
         }%>
         function submitForm()//Submit function with checkbox determined value
              if(document.login.rememberChk.checked)
                   document.login.remember.value = 1;
              else
                   document.login.remember.value = 0;
              document.login.submit();
         document.login.email.value="<%=email%>";
         document.login.password.value="<%=password%>";
    </script>
    </html>
    login.jsp
    <%@ page contentType="text/html; charset=iso-8859-1" language="java"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Home Page</title>
    </head>
    <body>
    <a href="logout.jsp">Logout</a><br />
    <%
         String email;
         String password;
         String remember;
         email = request.getParameter("email".toString());
         password = request.getParameter("password".toString());
         remember = request.getParameter("remember");
          *if Remember Checkbox is Checked
          *then Save Email and passwod into Cookie
          *and Add Cookies into response/Client Device
         if(remember.equals("1")){
              Cookie pass = new Cookie("password",password);
              Cookie emailAdd = new Cookie("email",email);
              //Setting maximum Expiry Date Of Cookies
              pass.setMaxAge(365);
              emailAdd.setMaxAge(365);
              //Make Persistent Cookie onto Client Device
              response.addCookie(pass);
              response.addCookie(emailAdd);
    %>
    <h4>Welcome - <%=email%> </h4>
    Your password is : <%=password%> <br />
    </body>
    </html>
    Home.jsp
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <html>
    <%
    Cookie cookies [] = request.getCookies ();//Get All Cookies from Client Device
    if (cookies != null){//Check cookies are available
         for (int i = 0; i < cookies.length; i++){
              if (cookies .getName().equals("password")){
                   Cookie cookie = cookies[i];
                   cookie.setMaxAge(0);
                   response.addCookie(cookie);
                   break;
         for (int i = 0; i < cookies.length; i++){
              if (cookies [i].getName().equals ("email")){
                   Cookie cookie = cookies[i];
                   cookie.setMaxAge(0);
                   response.addCookie(cookie);
                   break;
    response.sendRedirect("login.jsp");
    %>
    </html>
    logout.jsp

  • Using Quicken to manage a bank account, I get an error message from the bank that cookies and javascript must be enabled, but I don't get that message when I connect with Internet Explorer.

    Firefox allows me to get the bank home page through Quicken. But when I try to login, the error message appears saying "cookies and javascript" must be enabled. I have Java on my system, but in Firefox under "tools/options/ I don't find any way to "enable" javascript. I have enabled "cookies".
    I have no problem logging in at the bank site using Internet Explorer, but to use it, I have to designate it as the "default browser" before connecting through Quicken. I'd rather keep Firefox as the default.
    A bank tech representative was unable to find any commands in Firefox that would deal with this problem, although she clearly had manuals for both Internet Explorer and Firefox. So she concluded that I would have to use Explorer for this operation, since it allowed control of security level settings. She said that in Explorer, security level should be set to medium.
    Is there some similar control in Firefox?

    Firefox uses the same "security level" setting that is set in IE.
    Tools > Options > '''Content''' <br />
    Is '''Enable Javascript''' check-marked?
    http://kb.mozillazine.org/JavaScript_is_not_Java
    If that doesn't solve your problem, do you have that problem when running in the Firefox SafeMode? <br />
    [http://support.mozilla.com/en-US/kb/Safe+Mode] <br />
    ''Don't select anything right now, just use "Continue in SafeMode."''
    If not, see this: <br />
    [http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes]

  • When trying to get onto my email, the following statement comes uip: "We are sorry, but you will need to enable cookies and Javascript to use your Username with this site. I click "here" but nothing happens. How do I enable cookies amd Javascript?

    Trying to get t my email, this comes up: We are sorry, but you will need to enable cookies and Javascript to use your Username with this site.
    How do I do this?
    George Szanto<br />
    [email protected]

    see similar question answered at https://support.mozilla.com/questions/836913
    To be notified of updates to a question whether it is your problem or not simply click on the "Get email notifications" and follow directed choice. Only the original poster can mark as solved, so there should be a slight difference in choice as an original poster and where you latch onto another question. The notifications only apply to the specific question where entered.

  • Using CSS and Javascript to display a div with flash in it, mozilla reloads the flash file!

    I am using CSS and Javascript to display a div with an
    embedded flash object in it. Mozilla Firefox reloads the flash file
    when the div is displayed! (I dont want this to happen, as it's
    unexpected functionality, my expectation would be that the flash
    file would not change it's state at all, and would remain in
    whatever state it was left in.)
    I was wondering if anyone has come across this issue and is
    there something I can do to prevent this from occurring?
    To be more specific, I have a single HTML page with 8 flash
    files embedded in it (yeah I know, it's a bit much). I am then
    using CSS and Javascript to display (via a numbered link (with an
    id)) an equivalent numbered div tag containing the flash file.
    Mozilla Firefox reloads the flash object that is in the div.
    Internet Explorer will not do this and will instead, load the flash
    object only upon initial view of the flash object. All subsequent
    links (in IE) will NOT reload the flash object on the page. I'm
    guessing this is some kind of difference in the flash player as an
    Active X object and the plugin, or is it just IE being clever? Or
    am I way off?
    Anyway, here is the code...

    I am using CSS and Javascript to display a div with an
    embedded flash object in it. Mozilla Firefox reloads the flash file
    when the div is displayed! (I dont want this to happen, as it's
    unexpected functionality, my expectation would be that the flash
    file would not change it's state at all, and would remain in
    whatever state it was left in.)
    I was wondering if anyone has come across this issue and is
    there something I can do to prevent this from occurring?
    To be more specific, I have a single HTML page with 8 flash
    files embedded in it (yeah I know, it's a bit much). I am then
    using CSS and Javascript to display (via a numbered link (with an
    id)) an equivalent numbered div tag containing the flash file.
    Mozilla Firefox reloads the flash object that is in the div.
    Internet Explorer will not do this and will instead, load the flash
    object only upon initial view of the flash object. All subsequent
    links (in IE) will NOT reload the flash object on the page. I'm
    guessing this is some kind of difference in the flash player as an
    Active X object and the plugin, or is it just IE being clever? Or
    am I way off?
    Anyway, here is the code...

  • Cookies and Javascript enabling

    Looking for instructions on enabling cookies and javascript on my IMAC.
    Can anyone please provide quick instruction ?

    By default, both should already be enabled. To check, open Safari's preferences. Under the Security tab, Enable JavaScript should already be checked. Under the Privacy tab, Allow from websites I visit is the default, and should already be the radio button choice.

  • I am using VPN, and Firefox is loading the page. Before I reinstall the new version, the VPN was working okay. Whta happened, what I am supposed to do?

    I am using VPN, and Firefox is loading the page. Before I reinstall the new version, the VPN was working okay. Whta happened, what I am supposed to do?
    I have to use the VPN to acess the site because of the limitatation , and it was working okay. When I do turn off the VPN, then the sites will open, but if I activate the VPN, then site will load for ever, but they won't load.
    Please advise me what to do?

    You might try using the add-on 'NoSquint' which allows numerous zoom options specific to each page you visit & keeps your settings - https://addons.mozilla.org/en-US/firefox/addon/nosquint/
    If you want to go back to 3.6x, you will find it here:
    http://www.mozilla.com/en-US/firefox/all-older.html
    In most cases you can simply "upgrade" (meaning downgrade) directly from the installation. It would be a good idea to save your passwords & bookmarks just to be on the safe side.

  • Website tell sme to enable cookies and Javascript when it is already enabled

    it concerns banking information...when I try to get into my bank account a window opens that tells me to enable cookies and Javascript when they are already enabled. This happens in both Firefox and Flock. I have tried unchecking them and then checking them but it doesn't work.
    == This happened ==
    A few times a week

    EXACTLY

  • Using facelets and javascript in dynamic regions

    Hello
    I'm using JDeveloper 11g 11.1.1.4.0.
    In the JDeveloper's documentation I found that there is the best parctice to use facelets.
    Now, I have next problem.
    I use dynamic region iside xhtml (facelets) page. Inside that dynamic region there is a view (jsff).
    The problem is that I can't use any custom JavaScript in that jsff.
    I tried next thing:
                <trh:script id="trhs1">
                    <af:resource type="javascript">
                      testm = function (event) {
                      alert('qqq');
                    </af:resource>
               </trh:script>
    <af:clientListener method="testm" type="dblClick"/>If that task-flow is placed inside jspx (not facelets) page, then all works.
    If that task-flow is placed inside xhtm (facelets) page, I have an error from browser that javascript's 'testm' method is not defined.
    I checked source code of the result html-page, and my javascript code really doesn't exists there.
    I can fix it by moving javascript code from the taskflow's jsff to surrounding xhtml page or using jspx page, but, maybe, there is another solution?
    Anatolii
    Edited by: Anatolii. on 11/4/2011 0:32

    Thank for replay, Shay
    I found that in Web User Interface Developer's Guide for Oracle ADF, 2 Getting Started with ADF Faces, Section 2.4, "Creating a View Page":
    Best Practice: Use Facelets to take advantage of the following:
    The Facelets layer was created specifically for JSF, which results in reduced overhead and improved performance during tag compilation and execution.
    Facelets is considered the primary view definition technology in JSF 2.0.
    Some future performance enhancements will only be available with Facelets
    Now I have facelets page with dynamic region, it works.
    I've decided to use facelets because of the forthcoming JDeveloper with JSF 2.0 and for performance improvements described above.
    Do you think it's better to use jspx?
    I have not found any limitations for facelets in Web User Interface Developer's Guide for Oracle ADF and Fusion Developer's Guide for Oracle ADF
    Anatolii

  • How to use Spry and Jquery on the same page.

    I'm using both spry (dataset) and jquery (datepicker) on my page. When I load the jquery script my dataset doesn't work.
    I've done some research and found that I need to insert an observer that tells jquery when the spry dataset is finished loading. Found this information at: http://forums.adobe.com/message/2899897. I've tried implementing this into my script but just doesn't seem to work. Below is the script from my site, how would I insert an observer into this script?
    <script type="text/javascript">
    <!--
    var ds1 = new Spry.Data.HTMLDataSet("/test/fsasearch_results_dynamic.php", "search_results");
    var ds2 = new Spry.Data.HTMLDataSet("/test/countstable_dynamic.php", "table");
    $(function() { $( "#datepicker" ).datepicker({ dateFormat: 'yy-mm-dd', beforeShowDay: nonWorkingDates, numberOfMonths: 2, minDate: +5, maxDate: +30});
        function nonWorkingDates(date){
            var day = date.getDay(), Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6;
            var closedDates = [[7, 29, 2009], [8, 25, 2010]];
            var closedDays = [[Saturday], [Sunday]];
            for (var i = 0; i < closedDays.length; i++) {
                if (day == closedDays[i][0]) {
                    return [false];
            for (i = 0; i < closedDates.length; i++) {
                if (date.getMonth() == closedDates[i][0] - 1 &&
                date.getDate() == closedDates[i][1] &&
                date.getFullYear() == closedDates[i][2]) {
                    return [false];
            return [true];
    //-->
    </script>

    Please post any SPRY related question in the SPRY forum.

  • Error using java and javascript

    I have a jsp page that links to a bean and is working fine (getting data from the database).
    On a html form I have a button with a picture that fires off javascript when clicked:
    <BUTTON TYPE=reset onclick=showinfo('<%=index%>')>
    <IMG SRC="http://localhost:8080/Portal/Images/q2.bmp" ALT="Info">
    </BUTTON>
    The javascript function just opens a new window and displays the text sent in:
    <Script Language=JavaScript>
    function showinfo(arrayindex)
    InfoWin=window.open("","InfoWin","width=345,height=220");
    InfoWin.document.write(arrayindex);
    return false;
    </Script>
    Well in the above example index is a number (pulled from the database using a java bean and javascript converts it into a string then the function displays it correctly. If I replace <%=index%> with regular text it works fine as well(because java isn't used to pull data)! The problem occurs when I retrieve text data from the database and send it to the function. The web page gives errors about a nonterminating string. But I can move the code to somewhere else on the form(as long as I don't send it to java script) and it will print the text to the screen. I can also view the source of the web page and the html shows the text from the data base as if I hard coded the text into the javascript!!!!!!!!!!!!!!!!!
    This must be a bug between java and javascript!
    -can pass numbers(from a database) between the two
    -can't pass text (from a database)between the two
    Any info would help!

    Found the problem myself!
    I am using an odbc connection to msaccess and the spaces in the text was messing things up!
    After taking out the spaces it worked again.

  • I have absolutely no use for "Events" in iPhoto: can I get rid of this concept? I am importing photos maybe one or a dozen times a day and cannot avoid creating a new event each time. Or can I?

    As my long question implies (sorry, should have kept it shorter) I have a problem with being forced to have Events in my iPhoto'11 9.2.3 (629.52) on my MacBook 10.6.8. My habit is to unload the camera constantly, whether I have taken a single shot or a whole series. Each new addition creates an Event which actually bothers me!
    Is there a way of avoiding this? If I erase an event from iPhoto the photos will disappear from the Library it seems ... Please help with your advice. Thanks! Sigrid.

    Thanks, OT!
    When I look at my odd(?) habits of dealing with iPhoto anyone will see that I have a very simplistic approach: I never let one single Library get bigger than 300 or 400 photos, then back it up as is and make a separate, manual backup of the different albums as named by myself on an external HD. Then I delete the Library as such from my Mac but can reinstate it from the backups as I please. The backups are properly labelled, of course.
    I get dizzy when I read about libraries of thousands of photos, of keywords, ratings, smart albums etc. because this just wouldn't apply to my so-called system. So instead of using Faces and Places, my album names show clearly what's in them - "skies and scenery" Euskadi, "bugs and birds at Fancourt", "inventories", "people" (separate for my circle of people and characters from media), "my dog" etc., usually a bunch of 20 albums or so depending on my whereabouts. Quite manageable!
    I've been doing just fine with this method and would recommend it ... but others are much brighter ;-) and use the offered (and to me too advanced) features of iPhoto, if they prefer these. Now that I know how to get rid of Events by merging them into one, I at least feel a little freer there.
    Well, it's 1:25AM my time, gotta go ...

  • Can't open web pdf files from my Reader DC because my IMac wants a completed license agreement to use Reader and I never saw that page during installation.

    Can't open web pdf files from my newly installed Reader DC because my IMac wants a completed license to use agreement to Reader, and I never saw that page during installation.  How do I get past this?

    You need to accept the EULA on first launch of the Reader DC application.
    Go to the Applications folder and launch Adobe Acrobat Reader DC. 
    This will bring up the EULA.
    Select the "Agree" button if you agree with the terms
    Assuming you selected the "Agree" button, Reader DC should open.
    You should now be able to open PDF files in your web browser.

  • Importing data from a .txt file and have Acrobat create new pages

    Hi everyone,
    I've created a form in Acrobat 9 to be used as an invoice. I want to be able to import data from an excel spreadsheet or .txt file into all the form fields. I know that I can go Forms > Manage form Data > Import Data to import 1 record at a time, but say I have about 50 invoices to populate, is there a way to import all the records at once and have acrobat create a new invoice for each of the customer's records?
    If there is a way, will it be compatible for Acrobat Reader users since this form will be used by someone who only has the Reader?
    Really appreciate any help.

    Sure.. this is what we use. "New Micro Right Click Tools"
    http://www.nowmicro.com/rct/

  • My iPod touch is lock and my brother was trying too use it and he  entered the wrong code  too many times

    IPod touchMy iPod touch is lock and my brother was trying too use it and he  entered the wrong code  too many times

    Ok
    I may be able to help you .
    If you backed up your iPod prior to it being locked you may be in luck.
    1. Hook it up to your Mac or PC
    2.Open iTunes
    3.Click on your iPod (on the left hand side somewhere)
    4.Click on restore (in the centre somewhere)
    5.follow the onscreen instructions
    Once you have restored the device there should be an option that says restore from back up.
    Click on that.
    Hopefully this works. If it doesn't please let me no.

Maybe you are looking for