一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

两种js获取当前域名代码

时间:2014-07-09 编辑:简简单单 来源:一聚教程网

今天给各位朋友介绍两种js获取当前域名

 代码如下 复制代码

//获取当前域名

1、window.location.host;
2、document.domain;

//获取当前页面地址

url = window.location.href;

例子

 代码如下 复制代码

补充:

获取当前域名信息

 代码如下 复制代码
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 );

热门栏目