0
0

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.

HTMLに書くURI

Last updated at Posted at 2020-04-21

基本的なことなのに

なんとなくで動いていたのだが、改めて調べて”へぇ”となったので。
お恥ずかしい。
基本的にはJSでのajax(xhr,fetch)とかでも同じこと

前提
こんなHTMLにアクセスしているとする
http://localhost/test/test.html

相対パス

  <a href="relative.html">LINK</a>
  <a href="./relative.html">同階層へのリンク</a>
  <a href="../relative.html">一つ上の階層へのリンク</a>

この時今のディレクトリ階層から相対パスとなり

一つ目、二つ目のリンク先は
http://localhost/test/relative.html
になる

三つ目のリンクは一つ上の階層を指すので、こんな感じになる。
http://localhost/relative.html

絶対パス

  <a href="/absolute.html">LINK</a>

この時リンク先はホスト名からの絶対パスとなり
http://localhost/absolute.html
になる

URL

  <a href="http://localhost/url/url.html">LINK</a>

この時リンク先はそのままURLで扱われるので
http://localhost/url/url.html
になる

これまで意識してこなかったけど、
こうなってるらしい。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?