50
49

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptでURLのパラメータを取得する

Posted at

今見ているページのURLのパラメータを取得することはよくやるけど、みんなどうやってるのか気になったから調べてみた。

http://ameblo.jp/linking/entry-10353146034.html
http://rem.bake-neko.net/prg/javascript3.html
window.locationで力づくでやるのがスタンダードっぽい。
(自分もそうやってる)

http://d.hatena.ne.jp/natu_n/20081220/1229756677
prototype.jsやjQueryのプラグインもあったけど、古いし、これのためだけに入れるのもなぁ。

とりあえず現状の解決策だけでも以下に載せておく。
なんか良いやり方があったら教えてほしい。

get_url_vars()->
function get_url_vars()
{
  var vars = new Object, params;
  var temp_params = window.location.search.substring(1).split('&');
  for(var i = 0; i <temp_params.length; i++) {
    params = temp_params[i].split('=');
    vars[params[0]] = params[1];
  }
  return vars;
}

50
49
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
50
49

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?