Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Javascript Timer

Javascript Timer

Scheduled Pinned Locked Moved ASP.NET
javascripttutorial
6 Posts 6 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    senthilsstil
    wrote on last edited by
    #1

    Hi Friends, I m having a timer in my page which decreases the time,i want to close the window automatically when the time reaches end.I have used window.close() but it asks me a message whether window should be close or not.Can any one tell me how to close the window automatically. Here is the Coding function startTimer1(h,m,s) { if(document.getElementById('txt').innerHTML=="00:00:00") { alert("Your time is Over,Now the Application is going to close"); //self.close(); window.close(); return false; } var today=new Date(); if(h=="0" && m=="0" && s=="0") { h=00; m=01; s=00; } else { if(s=="00") { s=59; if(m=="00" && h!="00") { h=parseInt(h)-1; m=59; } else if(m!="00" && h=="00") { m=parseInt(m)-1; } else if(m!="00" && h!="00") { m=parseInt(m)-1; } else if(s=="00" && m=="00") { if(h!="00") h=parseInt(h)-1; } } else s=parseInt(s)-1; } // add a zero in front of numbers<10 h=checkTime(h); m=checkTime(m); s=checkTime(s); document.getElementById('txt').innerHTML=h+":"+m+":"+s; t=setTimeout('startTimer1('+h+','+m+','+s+')',1000); } function checkTime(i) { if (i<10) { i="0" + i; } return i; }

    C J S A 4 Replies Last reply
    0
    • S senthilsstil

      Hi Friends, I m having a timer in my page which decreases the time,i want to close the window automatically when the time reaches end.I have used window.close() but it asks me a message whether window should be close or not.Can any one tell me how to close the window automatically. Here is the Coding function startTimer1(h,m,s) { if(document.getElementById('txt').innerHTML=="00:00:00") { alert("Your time is Over,Now the Application is going to close"); //self.close(); window.close(); return false; } var today=new Date(); if(h=="0" && m=="0" && s=="0") { h=00; m=01; s=00; } else { if(s=="00") { s=59; if(m=="00" && h!="00") { h=parseInt(h)-1; m=59; } else if(m!="00" && h=="00") { m=parseInt(m)-1; } else if(m!="00" && h!="00") { m=parseInt(m)-1; } else if(s=="00" && m=="00") { if(h!="00") h=parseInt(h)-1; } } else s=parseInt(s)-1; } // add a zero in front of numbers<10 h=checkTime(h); m=checkTime(m); s=checkTime(s); document.getElementById('txt').innerHTML=h+":"+m+":"+s; t=setTimeout('startTimer1('+h+','+m+','+s+')',1000); } function checkTime(i) { if (i<10) { i="0" + i; } return i; }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can't.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      • S senthilsstil

        Hi Friends, I m having a timer in my page which decreases the time,i want to close the window automatically when the time reaches end.I have used window.close() but it asks me a message whether window should be close or not.Can any one tell me how to close the window automatically. Here is the Coding function startTimer1(h,m,s) { if(document.getElementById('txt').innerHTML=="00:00:00") { alert("Your time is Over,Now the Application is going to close"); //self.close(); window.close(); return false; } var today=new Date(); if(h=="0" && m=="0" && s=="0") { h=00; m=01; s=00; } else { if(s=="00") { s=59; if(m=="00" && h!="00") { h=parseInt(h)-1; m=59; } else if(m!="00" && h=="00") { m=parseInt(m)-1; } else if(m!="00" && h!="00") { m=parseInt(m)-1; } else if(s=="00" && m=="00") { if(h!="00") h=parseInt(h)-1; } } else s=parseInt(s)-1; } // add a zero in front of numbers<10 h=checkTime(h); m=checkTime(m); s=checkTime(s); document.getElementById('txt').innerHTML=h+":"+m+":"+s; t=setTimeout('startTimer1('+h+','+m+','+s+')',1000); } function checkTime(i) { if (i<10) { i="0" + i; } return i; }

        J Offline
        J Offline
        Jesse Squire
        wrote on last edited by
        #3

        The best that you can do is call window.close and have the user answer the prompt. Modern browsers will not allow you to close the browser window without user consent as the browser belongs to the user, not to your application. The one exception, if memory serves me, is opening a modal popup window in Internet Explorer. I would recommend that you steer clear of this, if possible, as it relies on browser specific behavior. Not only will it bind your application to IE, but future versions of IE are not guaranteed to support it. Hope that helps. :)

        --Jesse

        "... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi

        E 1 Reply Last reply
        0
        • J Jesse Squire

          The best that you can do is call window.close and have the user answer the prompt. Modern browsers will not allow you to close the browser window without user consent as the browser belongs to the user, not to your application. The one exception, if memory serves me, is opening a modal popup window in Internet Explorer. I would recommend that you steer clear of this, if possible, as it relies on browser specific behavior. Not only will it bind your application to IE, but future versions of IE are not guaranteed to support it. Hope that helps. :)

          --Jesse

          "... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi

          E Offline
          E Offline
          eyeseetee
          wrote on last edited by
          #4

          If you don't want to close the window just direct the user to another page, this would make the app much better for the user. These days with tabbed browsing you could ask the user to close and it close the whole window, therefore annoying the user

          1 Reply Last reply
          0
          • S senthilsstil

            Hi Friends, I m having a timer in my page which decreases the time,i want to close the window automatically when the time reaches end.I have used window.close() but it asks me a message whether window should be close or not.Can any one tell me how to close the window automatically. Here is the Coding function startTimer1(h,m,s) { if(document.getElementById('txt').innerHTML=="00:00:00") { alert("Your time is Over,Now the Application is going to close"); //self.close(); window.close(); return false; } var today=new Date(); if(h=="0" && m=="0" && s=="0") { h=00; m=01; s=00; } else { if(s=="00") { s=59; if(m=="00" && h!="00") { h=parseInt(h)-1; m=59; } else if(m!="00" && h=="00") { m=parseInt(m)-1; } else if(m!="00" && h!="00") { m=parseInt(m)-1; } else if(s=="00" && m=="00") { if(h!="00") h=parseInt(h)-1; } } else s=parseInt(s)-1; } // add a zero in front of numbers<10 h=checkTime(h); m=checkTime(m); s=checkTime(s); document.getElementById('txt').innerHTML=h+":"+m+":"+s; t=setTimeout('startTimer1('+h+','+m+','+s+')',1000); } function checkTime(i) { if (i<10) { i="0" + i; } return i; }

            S Offline
            S Offline
            Sandilian
            wrote on last edited by
            #5

            hai Friend. Please add window.opener='x' code before window.close <script language="jscript" type="text/javascript"> function startTimer1(h,m,s) { var today=new Date(); if(h=="0" && m=="0" && s=="0") { h=00; m=01; s=00; } else { if(s=="00") { s=59; if(m=="00" && h!="00") { h=parseInt(h)-1; m=59; } else if(m!="00" && h=="00") { m=parseInt(m)-1; } else if(m!="00" && h!="00") { m=parseInt(m)-1; } else if(s=="00" && m=="00") { if(h!="00") h=parseInt(h)-1; } } else s=parseInt(s)-1; } // add a zero in front of numbers<10 h=checkTime(h); m=checkTime(m); s=checkTime(s); var timerText=h+":"+m+":"+s; document.getElementById("<%=txtTimerId.ClientID%>").innerText=timerText; if(timerText =="00:00:00") { alert("Your time is Over,Now the Application is going to close"); /// This is the Code I added here; window.opener='x'; window.close(); return true; } t=setTimeout('startTimer1('+h+','+m+','+s+')',1000); } function checkTime(i) { if (i<10) { i="0" + i; } return i; } </script>

            1 Reply Last reply
            0
            • S senthilsstil

              Hi Friends, I m having a timer in my page which decreases the time,i want to close the window automatically when the time reaches end.I have used window.close() but it asks me a message whether window should be close or not.Can any one tell me how to close the window automatically. Here is the Coding function startTimer1(h,m,s) { if(document.getElementById('txt').innerHTML=="00:00:00") { alert("Your time is Over,Now the Application is going to close"); //self.close(); window.close(); return false; } var today=new Date(); if(h=="0" && m=="0" && s=="0") { h=00; m=01; s=00; } else { if(s=="00") { s=59; if(m=="00" && h!="00") { h=parseInt(h)-1; m=59; } else if(m!="00" && h=="00") { m=parseInt(m)-1; } else if(m!="00" && h!="00") { m=parseInt(m)-1; } else if(s=="00" && m=="00") { if(h!="00") h=parseInt(h)-1; } } else s=parseInt(s)-1; } // add a zero in front of numbers<10 h=checkTime(h); m=checkTime(m); s=checkTime(s); document.getElementById('txt').innerHTML=h+":"+m+":"+s; t=setTimeout('startTimer1('+h+','+m+','+s+')',1000); } function checkTime(i) { if (i<10) { i="0" + i; } return i; }

              A Offline
              A Offline
              Ashish Sehajpal
              wrote on last edited by
              #6

              a window can be closed using javascript if and only if it has been opened by javascript i.e. POPUP windows

              Ashish Sehajpal

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups