SYNCERのロゴ
アイキャッチ画像

Location.search - クエリ

searchは、Locationのプロパティです。ロケーションのクエリを返します。

概要

名前
search
所属
Location
IDL
[Unforgeable] attribute USVString search;
仕様書
https://html.spec.whatwg.org/multipage/history.html#dom-location-search

説明

ロケーションのクエリを表す文字列。存在しない場合は空の文字列。代入すると、そのアドレスに遷移する。

チュートリアル

取得

// https://syncer.jp/page.html?hoge=aaa&fuga=bbb#piyo

location.search ;	// "?hoge=aaa&fuga=bbb"

代入

// https://syncer.jp/page.html?hoge=aaa&fuga=bbb#piyo

location.search = "?syncer=best" ;	// → https://syncer.jp/page.html?syncer=best#piyo

デモ

Location.searchのデモです。このページに、クエリを付けてアクセスしてみて下さい。

<!-- このコードは編集できます。 -->

<!DOCTYPE html>
<html>
<body>
<script>
var value = location.search ;

console.log( value ) ;
document.body.appendChild( new Text( value ) ) ;
</script>
</body>
</html>

サポート状況

ChromeFirefoxSafariEdgeIEOperaiOS SafariAndroid
  • Twitterでシェア
  • Facebookでシェア
  • Google+でシェア
  • はてなブックマークでシェア
  • pocketに保存
  • LINEでシェア
更新履歴
2017年10月8日 (日)
コンテンツを公開しました。