HLJ 发布于
2018-06-02 19:50:05

两种js获取当前域名代码

内容摘要:今天给各位朋友介绍两种js获取当前域名 代码如下//获取当前域名1、window.location.host;2、document.domain;//获取当前页面地址url = window.location.href; 例子 代码如下<script language="javascript"...

 今天给各位朋友介绍两种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 );

当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2018-06-02/14.html
最后生成于 2023-06-18 18:28:43
此内容有帮助 ?
0