您当前位置: 首页 >  WEB技术 >  JS获取当前网址,JS获取当前域名URL ,JS获取网站完整路径页面
2013/4/16 18:17:10 分类:WEB技术

JS获取当前网址,JS获取当前域名URL ,JS获取网站完整路径页面

1.获取当前完整网址
<script type="text/javascript">
  
thisURL = document.URL;
thisHREF = document.location.href;
thisSLoc = self.location.href;
thisDLoc = document.location;
strwrite = " thisURL:  [" + thisURL + "]<br />"
strwrite += " thisHREF:  [" + thisHREF + "]<br />"
strwrite += " thisSLoc:  [" + thisSLoc + "]<br />"
strwrite += " thisDLoc:  [" + thisDLoc + "]<br />"
document.write( strwrite );
    </script>

2.获取当前域名信息
    <script type="text/javascript">

thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
strwrite = "  thisTLoc:  [" + thisTLoc + "]<br />"
strwrite += " thisPLoc:  [" + thisPLoc + "]<br />"
strwrite += " thisTHost:  [" + thisTHost + "]<br />"
strwrite += " thisHost:  [" + thisHost + "]<br />"
document.write( strwrite ); 
    </script>

3.获取当前页面
<script type="text/javascript">
 
tmpHPage = thisHREF.split( "/" );
thisHPage = tmpHPage[ tmpHPage.length-1 ];
tmpUPage = thisURL.split( "/" );
thisUPage = tmpUPage[ tmpUPage.length-1 ];
strwrite = " thisHPage:  [" + thisHPage + "]<br />"
strwrite += " thisUPage:  [" + thisUPage + "]<br />"
document.write( strwrite );
    </script>

本文由胡金金个人网站整理发布,转载请注明地址:http://www.hujinjin.com/info/215.html

凡标明来源于胡金金个人网站的文章,皆为本站整理发布,若转载此文必须附原文链接,对部分平台更改其文内容当自己原创者,胡金金个人网站将保留其追究权利!
个人资讯推荐
友情链接