返回当前 URL 的主机名和端口返回当前 URL 的主机名和端口<!DOCTYPE html><html><body> <h1>window.location 对象</h1> <p id="demo"></p> <script>document.getElementById("demo").innerHTML = "页面主机名是:" + window.location.hostname;</script> </body></html>