1
3

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.

window.locationを試してみよう

Posted at

はじめに

URLを解析して、クエリ文字列やハッシュを取得する方法を調べてみました。

window.locationでもクエリ文字列やハッシュを取得できそうだったので、それを試してみました。結果を先に述べると、locationでもクエリ文字列やハッシュを取得できました。

HOW

ブラウザで確認しました。
確認しやすいようにラップしました。

var href = location.href;
var hash = location.hash;
var host = location.host;
var hostname = location.hostname;
var port = location.port;
var pathname = location.pathname;
var protocol = location.protocol;
var search = location.search;

まとめ

string.splitを使ってクエリ文字列やハッシュを取得するよりもシンプルですね。使えるならば、locationオブジェクトを使いたいですね。

1
3
0

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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?