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. JavaScript
  4. Issue w/ Javascript inside 64 bit browser

Issue w/ Javascript inside 64 bit browser

Scheduled Pinned Locked Moved JavaScript
helpjavascripttools
3 Posts 3 Posters 0 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.
  • B Offline
    B Offline
    bgates1970
    wrote on last edited by
    #1

    The code below is suppose to auto logoff a user after 30 seconds. The problem is it works fine with 32 bit browsers but not at all in 64 bit browsers. The countDown() function gets called but it never executes the window.location. Any assistance would be appreciated! <script type='text/javascript'> var secondsRemaining = 30; var mhcTimer; function countDown() { secondsRemaining -= 1; if (secondsRemaining <= 0) { secondsRemaining = 0; window.location='login.aspx'; } } function startAutoLogoff() { if (mhcTimer) { return false; } else { mhcTimer = setInterval('countDown();', 1000); } } startAutoLogoff(); </script>

    D J 2 Replies Last reply
    0
    • B bgates1970

      The code below is suppose to auto logoff a user after 30 seconds. The problem is it works fine with 32 bit browsers but not at all in 64 bit browsers. The countDown() function gets called but it never executes the window.location. Any assistance would be appreciated! <script type='text/javascript'> var secondsRemaining = 30; var mhcTimer; function countDown() { secondsRemaining -= 1; if (secondsRemaining <= 0) { secondsRemaining = 0; window.location='login.aspx'; } } function startAutoLogoff() { if (mhcTimer) { return false; } else { mhcTimer = setInterval('countDown();', 1000); } } startAutoLogoff(); </script>

      D Offline
      D Offline
      Dennis E White
      wrote on last edited by
      #2

      my guess is that the assignment operator -= is not working properly and is probably only assigning the value of 1 to each time it executes. have you tried debugging your javascript code and inspecting the value after the assignment operator?

      as if the facebook, twitter and message boards weren't enough - blogged

      1 Reply Last reply
      0
      • B bgates1970

        The code below is suppose to auto logoff a user after 30 seconds. The problem is it works fine with 32 bit browsers but not at all in 64 bit browsers. The countDown() function gets called but it never executes the window.location. Any assistance would be appreciated! <script type='text/javascript'> var secondsRemaining = 30; var mhcTimer; function countDown() { secondsRemaining -= 1; if (secondsRemaining <= 0) { secondsRemaining = 0; window.location='login.aspx'; } } function startAutoLogoff() { if (mhcTimer) { return false; } else { mhcTimer = setInterval('countDown();', 1000); } } startAutoLogoff(); </script>

        J Offline
        J Offline
        jsc42
        wrote on last edited by
        #3

        One possibility is that other task running in the machine are killing the setInterval - this happens very often in Internet Explorer to the extent that the standard advice is to never use setInterval but to use setTimeout even though it is slightly more difficult. If you are running in a 64 bit processor, then I guess that performance is not an issue. But there are a few places where the JavaScript could be improved. * The only way that the secondsRemaining can go negative is if you run startAutoLogoff twice as you initialise the secondsRemaining at the top and not at the start of the auto logoff and you test for that condition. * There is a -= 1 idiom: it is the pre-/post-decrement operator (--). Just because some gurus don't like it in the middle of expressions, does not mean that it is verbotem as a stand alone construct. * Since JavaScript 1.2 (c 1998), the setInterval and setTimeout methods have supported functions as arguments as an alternative to expressions. These are more efficient, support closures, and prevent faux eval expressions which most gurus hate. * You have a lot of global variables (secondsRemaining, mhcTimer, countDown, and startAutoLogoff). It is possible that you may have a name clash somewhere else in your code that is causing the issue that you describe. Here is my equivalent code (I know that my layout and style offend some people):

        function startAutoLogoff()
        {
        if (! startAutoLogoff.mhcTimer) // Timer is not active
        {
        startAutoLogoff.secsRemaining =
        startAutoLogoff.timeoutTime; // No of secs to wait

            startAutoLogoff.mhcTimer    =
                window.setTimeout( startAutoLogoff.countDown, 1000 );
        }   // if
        

        } // startAutoLogoff

        startAutoLogoff.countDown = // Support routine for timing down
        function( )
        {
        if (--startAutoLogoff.secsRemaining) // Timed out?
        startAutoLogoff.mhcTimer = // No. Keep waiting
        window.setTimeout( startAutoLogoff.countDown, 1000 );
        else // Yes. Logoff
        window.location ='login.aspx';
        }; // startAutoLogoff.countDown

        // Static properties used by startAutoLogoff
        startAutoLogoff.mhcTimer = false;
        startAutoLogoff.timeoutTime = 30;
        startAutoLogoff.secsRemaining = startAutoLogoff.ti

        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