Location對象
location用于獲取或設置窗體的URL,并且可以用于解析URL。
語法:
location.[屬性|方法]
location對象屬性圖示:
location 對象屬性:
location 對象方法:
任務
在右邊編輯器script標簽內,獲取當前顯示文檔的URL,并輸出。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>location</title>
</head><script type="text/javascript">document.write(location.protocol+"//"+location.hostname+location.port+location.pathname+location.search+location.hash+"<br>"); function currenturl(){alert(window.location); } </script>
</head>
<body>
<input type="button" value="獲取網頁地址" οnclick="currenturl()">
</body>
</html>