- hash:返回 URL 中的哈希部分(以 # 开头)
- host:返回 URL 中的主机名和端口号
- hostname:返回 URL 中的主机名
- href:返回整个 URL(包括协议名,域名,端口号,路径,查询字符串等)
- pathname:返回 URL 中的路径
- port:返回 URL 中的端口号
- protocol:返回 URL 中的协议名
- search:返回 URL 中的查询字符串(以 ? 开头)
今天给各位朋友介绍两种js获取当前域名代码如下
//获取当前域名
1、window.location.host
2、document.domain
//获取当前页面地址
url
=
window.location.href
例子
代码如下
<script
language="javascript">
//获取域名
host
=
window.location.host
host2=document.domain
//获取页面完整地址
url
=
window.location.href
document.write("<br>host="+host)
document.write("<br>host2="+host2)
document.write("<br>url="+ur(www.45it.net)l)
</script>
补充:
获取当前域名信息
代码如下
thisTLoc
=
top.location.href
thisPLoc
=
parent.document.location
thisTHost
=
top.location.hostname
thisHost
=
location.hostname
strwrite
=
”
thisTLoc:
["
+
thisTLoc
+
"]”
strwrite
+=
”
thisPLoc:
["
+
thisPLoc
+
"]”
strwrite
+=
”
thisTHost:
["
+
thisTHost
+
"]”
strwrite
+=
”
thisHost:
["
+
thisHost
+
"]”
document.write(
strwrite
)
来源于: https://www.cnblogs.com/zhipeng007/p/10673105.html
属性 描述
hash设置或获取 href 属性中在井号“#”后面的分段。
host 设置或获取 location 或 URL 的 hostname 和 port 号码。
hostname 设置或获取 location 或 URL 的主机名称部分。
href 设置或获取整个 URL 为字符串。
pathname 设置或获取对象指定的文件名或路径。
port 设置或获取与 URL 关联的端口号码。
protocol 设置或获取 URL 的协议部分。
search设置或获取 href 属性中跟在问号后面的部分。