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 物件屬性:

location 物件方法:

新建檔案
<!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>
預覽
Clear
- 課程推薦
- 課件下載
課件暫不提供下載,工作人員正在整理中,後期請多關注該課程~ 















