location對象

location物件表示目前頁面的URL資訊。例如,一個完整的URL:

http://www.example.com:8080/path/index.html?a=1&b=2#TOP

可以用location.href取得。要取得URL各部分的值,可以這麼寫:

location.protocol; // 'http'
location.host; // 'www.example.com'
location.port; // '8080'
location.pathname; // '/path/index.html'
location.search; // '?a=1&b=2'
location.hash; // 'TOP'

要載入一個新頁面,可以呼叫location.assign()。如果要重新載入目前頁面,呼叫location.reload()方法非常方便。

location 物件屬性:

QQ截图20161012171542.png

location 物件方法:

QQ截图20161012171548.png

繼續學習
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>location</title> </head> <script type="text/javascript"> var myurl=window.location.href; document.write("当前网址:"+myurl); </script> </head> <body> </body>
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!