检查互联网是否使用 JavaScript/HTML 发送/接收数据包

发布于 2025-01-11 00:40:49 字数 1094 浏览 0 评论 0原文

我一直在编写一些 HTML 代码来告诉我互联网的状态,我设置了离线和在线事件,但我想检查我的互联网是否正在发送或接收数据包。我该如何使用 JavaScript 来做到这一点?我检查了所有地方,但我不知道如何在 JavaScript 中做到这一点。 (预先感谢!)

这是我的代码:

<!DOCTYPE html>
<html>
<body onoffline="myFunction(); myFunction12();" ononline="myFunction1(); myFunction02();"
onpacketsend="myFunction2(); setTimeout(() => {myFunction22}, 300);">

<h3 id="demo1">Online.</h3>

<h3 id="demo2">Sending/Recieving...</h3>

<h3 id="demo">Offline!</h3>


<script>
function myFunction() {
  document.getElementById("demo").style.color = "red";
}

function myFunction1() {
  document.getElementById("demo1").style.color = "green";
}

function myFunction2() {
  document.getElementById("demo2").style.color = "blue";
}


function myFunction02() {
  document.getElementById("demo").style.color = "black";
}

function myFunction12() {
  document.getElementById("demo1").style.color = "black";
}

function myFunction22() {
  document.getElementById("demo2").style.color = "black";
}

</script>

</body>
</html>

I have been making some HTML code to tell me the status of my internet, I have offline and online events set up but I want to check if my internet's sending or receiving packets. How would I do this using JavaScript? I checked everywhere but I can't figure out how to do this in JavaScript. (Thanks in advance!)

Here's my code:

<!DOCTYPE html>
<html>
<body onoffline="myFunction(); myFunction12();" ononline="myFunction1(); myFunction02();"
onpacketsend="myFunction2(); setTimeout(() => {myFunction22}, 300);">

<h3 id="demo1">Online.</h3>

<h3 id="demo2">Sending/Recieving...</h3>

<h3 id="demo">Offline!</h3>


<script>
function myFunction() {
  document.getElementById("demo").style.color = "red";
}

function myFunction1() {
  document.getElementById("demo1").style.color = "green";
}

function myFunction2() {
  document.getElementById("demo2").style.color = "blue";
}


function myFunction02() {
  document.getElementById("demo").style.color = "black";
}

function myFunction12() {
  document.getElementById("demo1").style.color = "black";
}

function myFunction22() {
  document.getElementById("demo2").style.color = "black";
}

</script>

</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_失温 2025-01-18 00:40:49

目前无法使用 Javascript/HTML 进行操作。不幸的是,这意味着您只能检查是否已连接到互联网,

因此我只能:

<body onoffline="myFunction();" ononline="myFunction1();"
">

It is not currently possible to do with Javascript/HTML. Unfortunatly this means you can only check to see if you are connected to the internet

so I can only:

<body onoffline="myFunction();" ononline="myFunction1();"
">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文