JavaScriptで、現在のページのクエリ情報(URLの末尾にある「?〜」)の文字を取得したい場合はlocationオブジェクトのsearchを使えば取得することができます。locationオブジェクトにはsearch以外にもhrefやhostNameといった便利なものがあります。ということでメモがてらエントリーしておきます。 こんな感じで使うことができます。以下はURLが「http://example.com/example.html?aa=sample」だった場合です。 var a = location.search; document.writeln(a); // 実行結果 ?aa=sample ただこれだと値に日本語などが含まれているとエンコードされてしまうのでdecodeURIComponentで取得した値をデコードしておくといいかもです。 var a = decodeURIC
![JavaScriptのlocation.searchでクエリ情報を取得してみる – bl6.jp](https://cdn-ak-scissors.b.st-hatena.com/image/square/d6e828b68611d4c1004e53e8da6167393f9d18a9/height=288;version=1;width=512/https%3A%2F%2Fbl6.jp%2Fwordpress%2Fwp-content%2Fuploads%2F2012%2F04%2Fjavascript-01.png)