Browser detection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SwapnilD
    New Member
    • Jan 2010
    • 41

    Browser detection

    I have a javascript function to log out users if they do not refresh page for 45 minutes.
    Code:
    (function() 
    {
      setTimeout('newWindow()',3000000);
      setTimeout('logout()', 3600000);
    }());
    But this function getting executed unexpectedly for SAFARI browser. As a workaround for this I decided to ignore this code for SAFARI browser by using a code which detect browser as mentioned below.
    Code:
    if (navigator.userAgent.indexOf("Safari")==-1 ) 
    		{
    (function() 
    {
    setTimeout('newWindow()',3000000);
    setTimeout('logout()', 3600000);
    }());
    }
    But the below mentioned line
    Code:
    if (navigator.userAgent.indexOf("Safari")==-1 )
    also detecting CHROME as a SAFARI.

    So the above code not getting executed for SAFARI as well as CHROME, But I want it to get executed for all the browser except SAFARI.

    Basically, I have two requirements.
    1. Function should work properly for SAFARI also
    OR
    2. Function should be executed for all the browser except SAFARI.

    Thanks in advance.

    Swapnil
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    what does 'getting executed unexpectedly for SAFARI browser' mean? could you elaborate on that a bit more?

    another note: to avoid useless evals you simply might call:
    Code:
    window.setTimeout( newWindow, 3000000 );
    the first param for the setTimeout-method is a function reference and the second is the delay ... when you pass a string to the function it needs to be evaluated which is just overhead.

    basicly the setTimeout() method should work in all browsers ... so please explain what 'unexpectedly' means in your case.

    kind regards

    Comment

    Working...