JavaScript ウィンドウの位置

JavaScript Window Location

window.location オブジェクトは、現在のページのアドレス (URL) を取得し、ブラウザーを新しいページにリダイレクトするために使用されます。

Window Location

window.location オブジェクトは、window プレフィックスを使用せずに記述することができます。 いくつかの例:

いくつかの例:

location.hostname は Web ホストのドメイン名を返します

location.pathname は現在のページのパスとファイル名を返します

location.port はポート (80 または 443) を返しますWeb ホスト

location。protocol は、使用される Web プロトコル (http:// または https://) を返します。

Window Location Href

location.href プロパティは、現在のページの URL を返します。

Instance

(現在のページの) URL 全体を返します:

<script>
document.write(location.href);
</script>

上記のコードの出力は次のとおりです:

http://php.cn/js/js-window-location.html

Window Location Pathname

location.pathname プロパティは URL のパス名を返します。

Instance

現在の URL のパス名を返します:

<script>
document.write(location.pathname);
</script>

上記のコードの出力は次のとおりです:

/js/js-window-location.html

Window Location Assign

location.assign() メソッドは新しいドキュメントを読み込みます。


学び続ける
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php(php.cn)</title>
</head>
<head>
<script>
function newDoc(){
window.location.assign("http://www.ask.php.cn")
}
</script>
</head>
<body>
<input type="button" value="" onclick="newDoc()">
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
图片放大关闭