2015-10-15 76 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