window.location.host
时间: 2023-12-09 08:04:16 浏览: 29
The window.location.host property returns the hostname and port number of the current page's URL.
For example, if the current page's URL is https://www.example.com:8080/index.html, then window.location.host will return "www.example.com:8080".
相关问题
如何拼接 window.location.protocol + window.location.host+/news/
可以使用如下代码实现拼接:
```
var url = window.location.protocol + "//" + window.location.host + "/news/";
```
其中,`window.location.protocol` 返回页面使用的协议(如 "http:" 或 "https:"),`window.location.host` 返回主机名和端口号(如 "www.example.com:80"),`/news/` 是需要拼接的路径。拼接后的完整 URL 存储在变量 `url` 中。
let host = `${window.location.protocol}//${window.location.host}`; let oauthHost = `${window.location.protocol}//${window.location.host}`;
这是一段 JavaScript 代码,包含两个变量声明语句。第一个变量 `host` 存储了当前网站的协议和域名,例如 `https://example.com`。第二个变量 `oauthHost` 也存储了当前网站的协议和域名,但通常用于 OAuth 认证相关的操作。这段代码使用了模板字符串语法,将协议和域名拼接成完整的 URL。