JavaScript 視窗位置
JavaScript?Window Location
window.location 物件用於取得目前頁(yè)面的位址 (URL),並將瀏覽器重新導(dǎo)向到新的頁(yè)面。
Window Location
window.location?物件在編寫(xiě)時(shí)可不使用 window 這個(gè)前綴。 一些範(fàn)例:
一些實(shí)例:
location.hostname 傳回web 主機(jī)的網(wǎng)域名稱
location.pathname 傳回目前頁(yè)面的路徑和檔名
location .port 傳回web 主機(jī)的連接埠(80 或443)
location.protocol 傳回所使用的web 協(xié)定(http:// 或https://)
Window Location Href
location.href 屬性傳回目前頁(yè)面的URL。
實(shí)例
傳回(目前頁(yè)面的)整個(gè)URL:
<script> document.write(location.href); </script>
以上程式碼輸出為:
http://php.cn/js/js-window-location.html
Window Location Pathname
location.pathname 屬性傳回URL 的路徑名。
實(shí)例
傳回目前URL 的路徑名稱:
<script> document.write(location.pathname); </script>
以上程式碼輸出為:
/js/js-window-location.html
Window Location Assign
#location. assign() 方法載入新的文件。