码迷,mamicode.com
首页 > 编程语言 > 详细

javascript获取当前路径

时间:2014-09-28 12:54:22      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:blog   io   os   ar   java   sp   div   on   c   

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>

javascript获取当前路径

标签:blog   io   os   ar   java   sp   div   on   c   

原文地址:http://www.cnblogs.com/llgjk/p/3997863.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!