43
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, jQuery でのURLの扱い方

Last updated at Posted at 2014-10-29

例えば
http://www.test.com:8082/index.php#tab2?foo=123
について
###JavaScriptの場合

Property Result
window.location.host www.test.com:8082
window.location.hostname www.test.com
window.location.port 8082
window.location.protocol http
window.location.pathname /index.php
window.location.href http://www.test.com:8082/index.php#tab2
window.location.hash #tab2
window.location.search ?foo=123

###jQueryの場合

Property Result
$(location).attr('host'); www.test.com:8082
$(location).attr('hostname'); www.test.com
$(location).attr('port'); 8082
$(location).attr('protocol'); http
$(location).attr('pathname'); /index.php
$(location).attr('href'); http://www.test.com:8082/index.php#tab2
$(location).attr('hash'); #tab2
$(location).attr('search'); ?foo=123
43
49
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
43
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?