gpt4 book ai didi

javascript - 通过javascript检查LAN连接

转载 作者:行者123 更新时间:2023-12-03 08:37:50 26 4
gpt4 key购买 nike

我在一台计算机上部署了一个 Web 应用程序,该计算机连接到 LAN 中的所有其他客户端计算机。当客户端通过浏览器使用网络应用程序时,我需要通过 JavaScript 检查每个请求是否存在 LAN 连接。

我在谷歌上搜索了很多相关内容,但所有内容都与互联网连接有关,而不是与局域网连接有关。提前致谢。

最佳答案

试试这个:对我有用:)

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

关于javascript - 通过javascript检查LAN连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33140213/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com