Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  javascript  >  正文 JS获取当前网址 当前域名URL 完整路径页面地址的实现代码

JS获取当前网址 当前域名URL 完整路径页面地址的实现代码

发布时间:2014-09-19   编辑:www.jquerycn.cn
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">
/**
 * 当前域名信息
 * site www.jbxue.com
*/
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"> 
/**
 * 当前页面地址
 * site www.jbxue.com
*/
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>

您可能感兴趣的文章:
获取当前页面的完整URL的php代码有哪些
JS获取当前网址 当前域名URL 完整路径页面地址的实现代码
获取当前页面的完整URL(php与js实现)
php 获取完整url地址实例详解
php获取当前页面的完整url
php获取站点的来路域名的方法
PHP获取域名的几个全局变量
php 获取当前页面地址
PHP获取当前网址及域名的代码
php获取当前页面url地址及参数

[关闭]