close

http://function1122.blogspot.com/2008/04/javascript.html

---

JavaScript 取得目前網址 (以及其他資訊)

FUNction 於 2008/4/30 下午9:05 發表
我是參考[這篇],其實這些技巧很好用,比如用在探測自己在何方(啥!?)

假設現在我有個網頁,網址是:http://functionlab.org:80/tools/tcpproxy.php?user=FUNction#showscript
如果這網頁上有以下JavaScript 程式碼

<script type="text/javascript">
//http://www.w3schools.com/htmldom/dom_obj_location.asp
document.write("location.href : "+location.href+"<br/>");
document.write("location.protocol : "+location.protocol+"<br/>");
document.write("location.hostname : "+location.hostname+"<br/>");
document.write("location.host : "+location.host+"<br/>");
document.write("location.port : "+location.port+"<br/>");
document.write("location.pathname : "+location.pathname+"<br/>");
document.write("location.search : "+location.search+"<br/>");
document.write("location.hash : "+location.hash+"<br/>");
</script>


那該網頁會顯示:
location.href : http://functionlab.org:80/tools/tcpproxy.php?user=FUNction#showscript
location.protocol : http
location.hostname : functionlab.org
location.host : functionlab.org:80
location.port : 80
location.pathname : /tools/tcpproxy.php
location.search : ?user=FUNction
location.hash : #showscript

天哪!! 真是方便 :-) 
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 dizzy03 的頭像
    dizzy03

    碎碎念

    dizzy03 發表在 痞客邦 留言(0) 人氣()