69
68

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

document.createElementでaオブジェクトを作ってそのオブジェクトのプロパティを使う!

uri.js
var parser = document.createElement('a');
parser.href = "http://hogehoge:8080/pathname/?search=test#hash";
 
parser.protocol; // => "http:"
parser.hostname; // => "hogehoge"
parser.port;     // => "8080"
parser.pathname; // => "/pathname/"
parser.search;   // => "?search=test"
parser.hash;     // => "#hash"
parser.host;     // => "hogehoge:8080"
69
68
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
69
68

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?