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);