转自【春素秋页】实用的js获取当前域名地址url

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>

测试:<p style="color: #ffffff">文章来源:<a style="color: #ffffff" href="http://www.wangjinzhan.com">金战网-和家长成长,伴孩子成长</a> <SCRIPT>var b=document;var c=window.location.href;b.write(c);</SCRIPT></p>

你可能感兴趣的:(转自【春素秋页】实用的js获取当前域名地址url)