Nov 20

js取得url, javascript获取当前页面url值, js获取域名 不指定

felix021 @ 2007-11-20 20:07 [IT » 网络] 评论(0) , 引用(0) , 阅读(17863) | Via 本站原创 | |
js取得当前url,javascript获取当前页面url值,js获取域名

转自http://hi.baidu.com/educast/blog/item/6f57d6ca80e7e744f21fe7b0.html

如果获取“当前”域名

host = window.location.host;
url=document.domain;  
url = window.location.href;


取得完整url路径: 用以下代码可以完整验证结果:


[codes=xml]
<table width=100% cellpadding=0 cellspacing=0 border=0 >
<script>  
thisURL = document.URL;  
thisHREF = document.location.href;  
thisSLoc = self.location.href;  
thisDLoc = document.location;  
strwrite = "<tr><td valign=top>thisURL: </td><td>[" + thisURL + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisHREF: </td><td>[" + thisHREF + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisSLoc: </td><td>[" + thisSLoc + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisDLoc: </td><td>[" + thisDLoc + "]</td></tr>"  
document.write( strwrite );  
</script>  
thisDLoc = document.location; <BR>
thisURL = document.URL; <BR>
thisHREF = document.location.href; <BR>
thisSLoc = self.location.href;<BR>
<script>  
thisTLoc = top.location.href;  
thisPLoc = parent.document.location;  
thisTHost = top.location.hostname;  
thisHost = location.hostname;  
strwrite = "<tr><td valign=top>thisTLoc: </td><td>[" + thisTLoc + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisPLoc: </td><td>[" + thisPLoc + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisTHost: </td><td>[" + thisTHost + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisHost: </td><td>[" + thisHost + "]</td></tr>"  
document.write( strwrite );  
</script>  
thisTLoc = top.location.href; <BR>
thisPLoc = parent.document.location; <BR>
thisTHost = top.location.hostname; <BR>
thisHost = location.hostname;<BR>
<script>  
tmpHPage = thisHREF.split( "/" );  
thisHPage = tmpHPage[ tmpHPage.length-1 ];  
tmpUPage = thisURL.split( "/" );  
thisUPage = tmpUPage[ tmpUPage.length-1 ];  
strwrite = "<tr><td valign=top>thisHPage: </td><td>[" + thisHPage + "]</td></tr>"  
strwrite += "<tr><td valign=top>thisUPage: </td><td>[" + thisUPage + "]</td></tr>"  
document.write( strwrite );  
</script><tr><td> [/codes]

运行如下:
thisURL:   [http://www.sinoeb.cn/js/js%BB%F1%C8%A1url.html]
thisHREF:   [http://www.sinoeb.cn/js/js%BB%F1%C8%A1url.html]
thisSLoc:   [http://www.sinoeb.cn/js/js%BB%F1%C8%A1url.html]
thisDLoc:   [http://www.sinoeb.cn/js/js%BB%F1%C8%A1url.html]
thisDLoc = document.location;
thisURL = document.URL;
thisHREF = document.location.href;
thisSLoc = self.location.href;
thisTLoc:   [http://www.sinoeb.cn/js/js%BB%F1%C8%A1url.html]
thisPLoc:   [http://www.sinoeb.cn/js/js%BB%F1%C8%A1url.html]
thisTHost:   [www.sinoeb.cn]
thisHost:   [www.sinoeb.cn]
thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
thisHPage:   [js%BB%F1%C8%A1url.html]
thisUPage:   [js%BB%F1%C8%A1url.html]





欢迎扫码关注:




转载请注明出自 ,如是转载文则注明原出处,谢谢:)
RSS订阅地址: https://www.felix021.com/blog/feed.php
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   *非必须
网址   电邮   [注册]