JS浏览器对象-Location对象

1、返回web主机的域名

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="UTF-8">
 5 <title>uvi</title>
 6      <link rel="stylesheet" href="style.css" type="text/css">
 7 </head>
 8 <body>
 9   
10    <button id="btn" onclick="getLoc()">按钮</button>
11    <p id="ptime"></p>
12    <script>
13       function getLoc(){
14           //返回web主机的域名
15           document.getElementById("ptime").innerHTML = window.location.hostname;
16       }
17    </script>
18    
19 </body>
20 </html>

2、返回web主机的域名

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="UTF-8">
 5 <title>uvi</title>
 6      <link rel="stylesheet" href="style.css" type="text/css">
 7 </head>
 8 <body>
 9   
10    <button id="btn" onclick="getLoc()">按钮</button>
11    <p id="ptime"></p>
12    <script>
13       function getLoc(){
14           //返回web主机的域名
15           document.getElementById("ptime").innerHTML = window.location.pathname;
16       }
17    </script>
18    
19 </body>
20 </html>

其他方式类似。

原文地址:https://www.cnblogs.com/UniqueColor/p/5756416.html