2015-10-15 80 views
0

我在一臺連接到局域網中所有其他客戶機的機器上部署了一個Web應用程序。當客戶端通過瀏覽器使用Web應用程序時,我需要檢查每個請求是否存在LAN連接。通過javascript檢查局域網連接

我對此有很多瞭解,但所有的內容都是關於互聯網連接,而不是關於局域網連接。提前致謝。

+0

做這些其他的機器上運行的某種在他們的應用程序或API服務的? –

+0

@BrijRajSingh不,這只是使用瀏覽器訪問網絡應用程序。 – Subash

+0

我認爲你需要看網絡信息API - https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API – caasjj

回答

1

試試這個:對我的作品:)

function hostReachable() { 

    // Handle IE and more capable browsers 
    var xhr = new (window.ActiveXObject || XMLHttpRequest)("Microsoft.XMLHTTP"); 
    var status; 

    // Open new request as a HEAD to the root hostname with a random param to bust the cache 
    xhr.open("HEAD", "//" + window.location.hostname + "/?rand=" + Math.floor((1 + Math.random()) * 0x10000), false); 

    // Issue request and handle response 
    try { 
    xhr.send(); 
    return (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304); 
    } catch (error) { 
    return false; 
    } 

} 

Reference