2012-05-16 2 views
1

IE 인스턴스를 사용하는 응용 프로그램을 위해 몇 초마다 인터넷 연결을 확인하기 위해 Ajax를 사용하고 있습니다. 그러나 낮은 대역폭 때문에 내 인터넷 탐색기가 충돌합니다.자바 스크립트의 인터넷 연결을 확인하는 모범 사례

Internet Explorer의 충돌을 방지하고 성능을 향상시킬 수 있도록 인터넷 연결을 확인하는 가장 좋은 방법은 무엇입니까?

인터넷 연결을 확인하려면 다음 코드를 사용하고 있습니다. 나는 JQuery와 파일을 얻을 곳에서

http://tomriley.net/blog/archives/111 - :

의 설명

는에서 제공됩니다.

(function ($) { 

     $.fn.checkNet = function (intCheckInterval, strCheckURL) { 
      if (typeof (intCheckInterval) === 'undefined') { 
       var intCheckInterval = 5 
      } if (typeof (strCheckURL) === 'undefined') { 
       var strCheckURL = window.location 
      } else if (strCheckURL.indexOf('http') === -1) { 
       var strCheckURL = 'http://' + strCheckURL 
      } intCheckInterval = intCheckInterval * 1000; function doRequest(strCheckURL) { 
       $.ajax({ url: strCheckURL, cache: false, success: function() { 
        if ($('#netWarn').length) { 
         $('#netWarn').fadeOut() 
        } $('.tempDisabled').removeAttr('disabled').removeClass('tempDisabled') 
       }, error: function() { 
        if (!$('#netWarn').length) { 


         $('body').prepend('<p id="netWarn">No internet connection detected, some features will be re-enabled when a connection is detected. </p>'); $('#netWarn').fadeIn() 

        } 

       } 
       }) 
      } setInterval(function() { 
       doRequest(strCheckURL) 
      }, intCheckInterval) 
     } 
})(jQuery); 

답변

0

내 플러그인은 요청 사이의 시간 길이를 인수로 사용합니다. 따라서 요청 간 간격을 10 초로하려면 다음 코드로 호출하십시오.

$.fn.checkNet(10); 

... 플러그인을 포함하면이 코드를 호출하십시오. 최근에 훨씬 더 효율적으로 작동하는 새 버전을 업로드했습니다.