Web Analytics Made Easy -
StatCounter View Time session limited - CodingForum

Announcement

Collapse
No announcement yet.

View Time session limited

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • View Time session limited

    Hello ppl!

    I would like to know if somebody can help me out. I need a script to put in a webpage, with a time limitation. I have a page that i just want to the "user" have 5 minutes to be on that page, and he could also see that time displaying... When it finish (the 5 minutes) he goes directly to another page( a page that says the user has to login again.)

    If someone knows a good script i would like to know please

    Thanks in advanced!!!
    Alex Vasconcelos

  • #2
    Here ya go, this should work for ya


    ----------


    <script language="javascript">

    var running = false
    var endTime = null
    var timerID = null

    function timer(){

    running=true
    now = new Date()
    now = now.getTime()
    endTime = now+(1000*300*1)
    endIt()
    }

    function endIt(){
    var now = new Date()
    now = now.getTime()
    if(endTime - now <=0){

    //this is where you put the href to the login page
    alert("You have to login again")
    location.href="Login.html"

    }else{
    var delta = new Date(endTime - now)
    var min = delta.getMinutes()
    var sec = delta.getSeconds()
    var Time = min
    Time+=((sec <10)?":0" : ":")+sec
    document.forms[0].timeuser.value=Time
    if(running){
    timerID = setTimeout("endIt()",1000)
    }
    }
    }
    window.onload=timer
    </script>

    <form>
    <input type="text" name="timeuser">
    </form>

    ---------


    HappyScripting
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

    Comment


    • #3
      THANKS MAN!! but can i make this a .js like time.js and put in all my 50 webpages... and in another frame make or put the form? i have a frame that have only the menu bar, and i want to put the time there... the other frame run the selected links from the menu, and there i can put the time.js... Can i do it? If you can please help me ...


      Many thanks!!!
      Alex Vasconcelos

      Comment


      • #4
        Sure,

        To make it a .js (since i can't attach it to thread)

        just copy this and past it into notepad(or somethin)
        and save it as time.js(like you said)

        --------------

        var running = false
        var endTime = null
        var timerID = null

        function timer(){

        running=true
        now = new Date()
        now = now.getTime()
        endTime = now+(1000*300*1)
        endIt()
        }

        function endIt(){
        var now = new Date()
        now = now.getTime()
        if(endTime - now <=0){

        //this is where you put the href to the login page
        alert("You have to login again")
        parent.framename.location.href="Login.html"

        }else{
        var delta = new Date(endTime - now)
        var min = delta.getMinutes()
        var sec = delta.getSeconds()
        var Time = min
        Time+=((sec <10)?":0" : ":")+sec
        document.forms[0].timeuser.value=Time
        if(running){
        timerID = setTimeout("endIt()",1000)
        }
        }
        }
        window.onload=timer

        -----------------------

        I have boldfaced the frame part. What that will do is when the time is up it will put the login page into the frame you specify.(the name of the frame)

        Make sure to have the correct path to the .js file
        <script language="javascript" src="time.js">
        </script>




        ++++++++

        If this isn't what you were saying sorry, just explain it in a little more detail and i'll fix it okay
        CYWebmaster.com - See why we dot com!!
        ACJavascripts.com - Cut & Paste Javascripts!
        SimplyProgram.com - Personal Blog

        Comment


        • #5
          <html>
          <head>
          <title>test</title>
          <script type="text/javascript">



          var ctid,ctint=1000,ctr=2*(ctint),ctmax=1000*(ctint),ctri=0*(ctint),ctmaxi=600*(ctint),wmax=0;
          function startCrono(){document.all.CTPM.innerHTML="Tempo de sessمo 1%";wmax=document.images["cronoM"].width;ctid=setInterval(mais,ctint);mais();return true;}
          function mais() {if (ctr<ctmax && ctri<ctmaxi) {ctr+=ctint;ctri+=ctint;} else clearInterval(ctid);var p=0,i=0,cm,c;if (ctr/ctmax>ctri/ctmaxi) {cm=ctmax;c=ctr} else {cm=ctmaxi;c=ctri};p=parseInt(100*(cm-c)/cm,10);i=parseInt(wmax-c*wmax/cm);document.all.CTPM.innerHTML="Tempo de sessمo "+p+"%";document.images["cronoM"].width=i;}
          </script>
          </head>
          <body BGCOLOR="#FFFFFF" MARGINWIDTH="3" MARGINHEIGHT="0" topmargin="0" leftmargin="2">

          <table height="15" cellpading="0" align="left" width="112">



          <tr valign="bottom">
          <td>
          <table cellspacing="0" border="0" cellpadding="0" width="90%">
          <tr>
          <td align="right" true width="12"></td>
          <td> <font face="arial" size="1" color="#004000">
          <P name="CTPM" id="CTPM">Tempo de sessمo 1%</P>
          </font> </td>
          </tr>
          <tr>
          <td align="right" true width="12"></td>
          <td bgcolor="#205319" height="6pxs" width="100%"><IMG SRC="images/arrow.gif" name="cronoM" width="10" height="10" border="0"></td>
          </tr>
          </table>
          </table>
          <script language="javascript">startCrono();</script>
          </body>
          </html>



          See this code, what do you think? I think is nice! i just want to make it go to the url ofthe frame correct when it stops (the 5 minutes) What do you think i have to do? Can you help me out? With an alert.... saying it´s need to relogin...
          Alex Vasconcelos

          Comment


          • #6
            I can't really understand the code, so could you post it again but put it line by line

            like:
            function go(){
            //comments
            }

            not function go(){//comments}function inti(){//comments}


            CYWebmaster.com - See why we dot com!!
            ACJavascripts.com - Cut & Paste Javascripts!
            SimplyProgram.com - Personal Blog

            Comment


            • #7
              var ctid,ctint=1000,ctr=2*(ctint),ctmax=1000*(ctint),c
              tri=0*(ctint),ctmaxi=600*(ctint),wmax=0;

              function startCrono()
              {document.all.CTPM.innerHTML="Tempo de sessمo 1%";wmax=document.images["cronoM"].width;ctid=setInterval(mais,ctint);
              mais();
              return true;}

              function mais()
              {if (ctr<ctmax && ctri<ctmaxi) {ctr+=ctint;ctri+=ctint;} else clearInterval(ctid);var p=0,i=0,cm,c;if (ctr/ctmax>ctri/ctmaxi) {cm=ctmax;c=ctr}
              else {cm=ctmaxi;c=ctri};p=parseInt(100*(cm-c)/cm,10);
              i=parseInt(wmax-c*wmax/cm);
              document.all.CTPM.innerHTML="Tempo de sessمo "+p+"%";document.images["cronoM"].width=i;
              }
              </script>

              Like this!?
              Alex Vasconcelos

              Comment


              • #8
                Yea that did fine


                Heres the code -- look at the boldface, thats what you custmize for the frameName & page

                ----------

                <script language="javascript">

                var Location="LoginPage.html"
                var FrameName="FramesName"

                var ctid,ctint=1000,ctr=2*(ctint),ctmax=1000*(ctint),c
                var ctri=0
                tri=0*(ctint),ctmaxi=600*(ctint),wmax=0;

                function startCrono() {
                document.all.CTPM.innerHTML="Tempo de sessمo 1%";
                wmax=document.images["cronoM"].width;ctid=setInterval(mais,ctint);
                mais();
                return true;
                }

                function mais() {
                if (ctr<ctmax && ctri<ctmaxi) {
                ctr+=ctint;
                ctri+=ctint;
                } else {
                clearInterval(ctid);
                var p=0,i=0,cm,c;
                eval("parent."+FrameName+".location.href="+Location)
                }
                if (ctr/ctmax>ctri/ctmaxi) {
                cm=ctmax;c=ctr
                } else {
                cm=ctmaxi;c=ctri;
                }
                p=parseInt(100*(cm-c)/cm,10);
                i=parseInt(wmax-c*wmax/cm);
                document.all.CTPM.innerHTML="Tempo de sessمo "+p+"%";document.images["cronoM"].width=i;
                }
                </script>


                <table height="15" cellpading="0" align="left" width="112">



                <tr valign="bottom">
                <td>
                <table cellspacing="0" border="0" cellpadding="0" width="90%">
                <tr>
                <td align="right" true width="12"></td>
                <td> <font face="arial" size="1" color="#004000">
                <P name="CTPM" id="CTPM">Tempo de sessمo 1%</P>
                </font> </td>
                </tr>
                <tr>
                <td align="right" true width="12"></td>
                <td bgcolor="#205319" height="6pxs" width="100%"><IMG SRC="images/arrow.gif" name="cronoM" width="10" height="10" border="0"></td>
                </tr>
                </table>
                </table>
                <script language="javascript">startCrono();</script>

                ----------------

                var FrameName=The Name of the Frame you want the page to go to

                var Location=The Page you want to go to the frame. like: LoginPage.html

                Hope this works for ya
                CYWebmaster.com - See why we dot com!!
                ACJavascripts.com - Cut & Paste Javascripts!
                SimplyProgram.com - Personal Blog

                Comment


                • #9
                  And if i do like this : tiempo_2.js

                  and put at the html page :

                  first in the head : <HEAD>
                  <!--cp002_relacion_ctas_POR.jsp-->
                  <title>BBVA - Contas à Ordem - Detalhe e Saldo da Conta</title>
                  <LINK rel=STYLESHEET type='text/css' href="estilos/tablas.css">
                  <script language="Javascript" src="js/banner.js"> </script>
                  <script language="Javascript" src="js/tiempo_2.js"> </script>

                  and i call in the same page the function... like this


                  <script language="javascript">startCrono()</script>
                  <script language="javascript">tabelatempo();</script>


                  but it doesn´t work.... always says an error of javascript at the call of <script language="javascript">startCrono()</script>

                  strange


                  - tiempo_2.js : this is the file js;

                  <script language="javascript">

                  var Location="/LogoutCBTFServlet?pag=controlSesion.jsp"
                  //var FrameName="FramesName"

                  var ctid,ctint=1000,ctr=2*(ctint),ctmax=1000*(ctint),c

                  var ctri=0
                  tri=0*(ctint),ctmaxi=600*(ctint),wmax=0;

                  function startCrono() {
                  document.all.CTPM.innerHTML="Tempo de sessمo 1%";
                  wmax=document.images["cronoM"].width;ctid=setInterval(mais,ctint);
                  mais();
                  return true;
                  }

                  function mais() {
                  if (ctr<ctmax && ctri<ctmaxi) {
                  ctr+=ctint;
                  ctri+=ctint;
                  } else {
                  clearInterval(ctid);
                  var p=0,i=0,cm,c;
                  eval("parent.location.href="+Location)
                  }
                  if (ctr/ctmax>ctri/ctmaxi) {
                  cm=ctmax;c=ctr
                  } else {
                  cm=ctmaxi;c=ctri;
                  }
                  p=parseInt(100*(cm-c)/cm,10);
                  i=parseInt(wmax-c*wmax/cm);
                  document.all.CTPM.innerHTML="Tempo de sessمo "+p+"%";document.images["cronoM"].width=i;
                  }


                  function tabelatempo ()
                  {

                  document.write ('<table height="15" cellpading="0" align="left" width="112">')

                  document.write ('<tr valign="bottom"><td>')
                  document.write ('<table cellspacing="0" border="0" cellpadding="0" width="90%"><tr>')

                  document.write ('<td align="right" true width="12"></td>')
                  document.write ('<td><font face="arial" size="1" color="#004000">')
                  document.write ('<P name="CTPM" id="CTPM">Tempo de sessمo 1%</P></font></td></tr>')

                  document.write ('<tr><td align="right" true width="12"></td> ')
                  document.write ('<td bgcolor="#205319" height="6pxs" width="100%"><IMG SRC="images/arrow.gif" name="cronoM" width="10" height="10" border="0"></td>')
                  document.write ('</tr></table></table>'
                  }
                  Alex Vasconcelos

                  Comment


                  • #10
                    /me just a whispers® to al3...
                    see this part???
                    </tr>
                    </table>
                    </table>

                    ifin' ya want your site to be just a viewable® in netscrap??? you havvve to just a close® the first table ya opened...

                    </tr>
                    </table>
                    </td></tr></table>

                    just a ps®...
                    youd havvve to just a change® this line tooo...
                    document.write ('</tr></table></table>'
                    The New JustaBuster Version 2.0 OR JustaBusta Lite V2.0
                    ...just a special® thanx kinda hugs to jkd n' nex ...:O)))

                    CommemorateWTC.com --Please lend your support

                    Comment


                    • #11
                      well, when you have a .js file you can't call the same function or variables from the .js into the page. So put the startCrono() function within the .js file. like so

                      ------------

                      var Location="/LogoutCBTFServlet?pag=controlSesion.jsp"
                      //var FrameName="FramesName"

                      var ctid,ctint=1000,ctr=2*(ctint),ctmax=1000*(ctint),c


                      var ctri=0
                      tri=0*(ctint),ctmaxi=600*(ctint),wmax=0;

                      function startCrono() {
                      document.all.CTPM.innerHTML="Tempo de sessمo 1%";
                      wmax=document.images["cronoM"].width;ctid=setInterval(mais,ctint);
                      mais();
                      return true;
                      }

                      function mais() {
                      if (ctr<ctmax && ctri<ctmaxi) {
                      ctr+=ctint;
                      ctri+=ctint;
                      } else {
                      clearInterval(ctid);
                      var p=0,i=0,cm,c;
                      eval("parent.location.href="+Location)
                      }
                      if (ctr/ctmax>ctri/ctmaxi) {
                      cm=ctmax;c=ctr
                      } else {
                      cm=ctmaxi;c=ctri;
                      }
                      p=parseInt(100*(cm-c)/cm,10);
                      i=parseInt(wmax-c*wmax/cm);
                      document.all.CTPM.innerHTML="Tempo de sessمo "+p+"%";document.images["cronoM"].width=i;
                      }


                      function tabelatempo ()
                      {

                      document.write ('<table height="15" cellpading="0" align="left" width="112">')

                      document.write ('<tr valign="bottom"><td>')
                      document.write ('<table cellspacing="0" border="0" cellpadding="0" width="90%"><tr>')

                      document.write ('<td align="right" true width="12"></td>')
                      document.write ('<td><font face="arial" size="1" color="#004000">')
                      document.write ('<P name="CTPM" id="CTPM">Tempo de sessمo 1%</P></font></td></tr>')

                      document.write ('<tr><td align="right" true width="12"></td> ')
                      document.write ('<td bgcolor="#205319" height="6pxs" width="100%"><IMG SRC="images/arrow.gif" name="cronoM" width="10" height="10" border="0"></td>')
                      document.write ('</tr></table></table>'
                      }

                      startCrono()


                      ----------

                      And in a .js file you cannot have <script language="javascript"> or </script>

                      a .js file is all javascript not tags. (like that)
                      I'm sure you know this i just had to make sure

                      Hope this works for ya
                      CYWebmaster.com - See why we dot com!!
                      ACJavascripts.com - Cut & Paste Javascripts!
                      SimplyProgram.com - Personal Blog

                      Comment


                      • #12
                        hI,

                        i have a page Html with :
                        <script language="Javascript" src="js/tiempo_2.js"></script>

                        and i have the tiempo_2.js with that code ( the last one) but it always says that exist an error in Javascript : document.all.BBVA. is null or not an object... errrrr...!!!! errrrrr.... argh!!! can you help me man!!!

                        thanks


                        All this works in a html page, but i need to have the js file, because i am going to put in a 50 webpages.... the tiempo_2.js!
                        Alex Vasconcelos

                        Comment


                        • #13
                          Okay i saw the problem and fixed it. If you follow these installation instructions it should work just great

                          ----------

                          1. Copy & Past the below code into the tiempo_2.js file

                          +++++++++


                          var Location="/LogoutCBTFServlet?pag=controlSesion.jsp"


                          var ctid,ctint=1000,ctr=2*(ctint),ctmax=1000*(ctint),c
                          var ctri=0
                          tri=0*(ctint),ctmaxi=600*(ctint),wmax=0;

                          function startCrono() {
                          document.all.CTPM.innerHTML="Tempo de sessمo 1%";
                          wmax=document.images["cronoM"].width;ctid=setInterval(mais,ctint);
                          mais();
                          return true;
                          }

                          function mais() {
                          if (ctr<ctmax && ctri<ctmaxi) {
                          ctr+=ctint;
                          ctri+=ctint;
                          } else {
                          clearInterval(ctid);
                          var p=0,i=0,cm,c;
                          location.href=Location
                          }
                          if (ctr/ctmax>ctri/ctmaxi) {
                          cm=ctmax;c=ctr
                          } else {
                          cm=ctmaxi;c=ctri;
                          }
                          p=parseInt(100*(cm-c)/cm,10);
                          i=parseInt(wmax-c*wmax/cm);
                          document.all.CTPM.innerHTML="Tempo de sessمo "+p+"%";document.images["cronoM"].width=i;
                          }


                          function tabelatempo (){

                          document.write ('<table height="15" cellpading="0" align="left" width="112">')

                          document.write ('<tr valign="bottom"><td>')
                          document.write ('<table cellspacing="0" border="0" cellpadding="0" width="90%"><tr>')

                          document.write ('<td align="right" true width="12"></td>')
                          document.write ('<td><font face="arial" size="1" color="#004000">')
                          document.write ('<P name="CTPM" id="CTPM">Tempo de sessمo 1%</P></font></td></tr>')

                          document.write ('<tr><td align="right" true width="12"></td> ')
                          document.write ('<td bgcolor="#205319" height="6pxs" width="100%"><IMG SRC="images/arrow.gif" name="cronoM" width="10" height="10" border="0"></td>')
                          document.write ('</tr></table></table>')
                          }

                          tabelatempo()
                          startCrono()


                          +++++++


                          2. Put this(below) into the html page where you want it to show ect.

                          ++++++++


                          <script language="javascript" src="tiempo_2.js">
                          </script>


                          +++++++++


                          It should work just great now.
                          CYWebmaster.com - See why we dot com!!
                          ACJavascripts.com - Cut & Paste Javascripts!
                          SimplyProgram.com - Personal Blog

                          Comment

                          Working...
                          X