ウィンドウlocation.hostname
例
現在のURLのホスト名を返します。
let hostname = location.hostname;
定義と使用法
プロパティは、URLのlocation.hostname
ホスト(IPアドレスまたはドメイン)を返します。
location.hostname
プロパティを設定して、新しいホスト名で同じURLに移動することもできます。
構文
ホスト名プロパティを返します。
location.hostname
ホスト名プロパティを設定します。
location.hostname = hostname
プロパティ値
Value | Description |
hostname | The hostname of the URL. |
戻り値
タイプ | 説明 |
文字列 | URLのホスト(IPアドレスまたはドメイン)。 |
ブラウザのサポート
location.hostname
すべてのブラウザでサポートされています:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |