天天看點

Javascrip中擷取頁面路徑

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 />" 

3.擷取目前頁面

tmpHPage = thisHREF.split( "/" ); 

thisHPage = tmpHPage[ tmpHPage.length-1 ]; 

tmpUPage = thisURL.split( "/" ); 

thisUPage = tmpUPage[ tmpUPage.length-1 ]; 

strwrite = " thisHPage: [" + thisHPage + "]<br />" 

strwrite += " thisUPage: [" + thisUPage + "]<br />" 

本文轉自 韬光星夜 51CTO部落格,原文連結:http://blog.51cto.com/xfqxj/477074,如需轉載請自行聯系原作者

繼續閱讀