HTML通过JavaScript获取访问连接,IP和端口
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Get IP Address</title>
<script>
function displayURL() {
var url = window.location.href; // 获取当前URL
document.getElementById("currentUrl").textContent = url; // 显示在HTML中
var hostname = window.location.hostname;// 获取当前ip
document.getElementById("currentIp").textContent = hostname; // 显示在HTML中
var port = window.location.port;// 获取当前端口
document.getElementById("currentPort").textContent = port; // 显示在HTML中
var host = window.location.host;//当前访问的IP和端口
document.getElementById("currentIphost").textContent = host; // 显示在HTML中
}
</script>
</head>
<body οnlοad="displayURL();">
<p>当前访问的URL是:<span id="currentUrl"></span></p>
<p>当前访问的IP是:<span id="currentIp"></span></p>
<p>当前访问的端口是:<span id="currentPort"></span></p>
<p>当前访问的IP和端口是:<span id="currentIphost"></span></p>
</body>
</html>
原文地址:https://blog.csdn.net/lgq1368853532/article/details/143920377
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!