English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
pathname属性は、URLのパス名を設定または返します。
パス名は、ホスト名から始まる文字列で、初期の「/”,URLのパスが続きます。
パス名属性を返す:
location.pathname
パス名属性を設定:
location.pathname = path
var x = location.pathname; document.querySelector("#output").innerHTML = x;テストを試してみる‹/›
すべてのブラウザが完全にサポートするpathname属性:
属性 | |||||
pathname | は | は | は | は | は |
値 | 説明 |
---|---|
path | URLのパスを指定する文字列 |
返り値: | URLのパスを示す文字列;パスがない場合は空文字列 |
---|
この例では、すべての位置属性を表示しています:
var txt = ""; txt += "<p>ホスト: " + location.host + "</p>"; txt += "<p>ホスト名: " + location.hostname + "</p>"; txt += "<p>href: " + location.href + "</p>"; txt += "<p>オリジン: " + location.origin + "</p>"; txt += "<p>パス名: " + location.pathname + "</p>"; txt += "<p>プロトコル: " + location.protocol + "</p>"; txt += "<p>検索: " + location.search + "</p>"; document.write(txt);テストを試してみる‹/›
位置参照:location.href属性
位置参照:location.host属性
位置参照:location.origin属性
位置参照:location.protocol属性