<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
body {
background: grey;
}
</style>
<script type="text/javascript">
function connected() {
console.log('连接成功,跳转到登录页');
window.location = 'http://localhost:83/login.html';
}
function tryAgain() {//测试60s大概尝试连接90次,可限定200次后不再尝试
console.log('连接失败,尝试再次连接');
document.getElementById('detect').src = 'http://localhost:83/images/logo.png?i=' + Math.random();//因为图片缓存原因,增加随机变量
}
</script>
</head>
<body>
<img id="detect" src="" onload="connected()" onerror="tryAgain()" />
</body>
</html>
如何用js判断是否能连通某网页
最新推荐文章于 2024-01-12 14:21:19 发布