HTML File Paths

HTML Living Standard

catalog.html ကို shop/pages ထဲ၊ product.svg ကို shop/images ထဲ၊ logo.svg ကို site ရဲ့ ထိပ်ဆုံး assets folder ထဲ သိမ်းထားတယ်လို့ စဉ်းစားပါ။ နမူနာတိုင်းမှာ ဒီဖိုင်တွဲပုံအတိုင်း browser က တွက်ထုတ်မယ့် URL ကို ပြထားပါတယ်။

ဒီစာမျက်နှာမှာ

./ နဲ့ ../ ကို လက်ရှိဖိုင်ကနေ တွက်ခြင်း

./ က လက်ရှိ folder ကနေ စပါတယ်။ ../ က အပေါ်က folder တစ်ဆင့်ကို ပြန်တက်ပါတယ်။ HTML ရဲ့ href နဲ့ src လို attribute တွေမှာ ဒီ path တွေ သုံးပါတယ်။ HTML ဖိုင်ကို ရွှေ့ရင် သူ့ folder ကနေ စတဲ့ path တွေ ပြန်စစ်ပါ။

စမ်းသပ်နည်း ဒီနမူနာကို .html ဖိုင်အသစ်အဖြစ် သိမ်းပြီး browser နဲ့ ဖွင့်ပါ။ ပြင်ပြီးတိုင်း save နဲ့ reload လုပ်ပါ။

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Resolve ./ and ../ from the current file</title>
</head>
<body>
<p id="examples"><a href="./hours.html">Hours</a> · <a href="../images/product.svg">Product image</a></p>
<p id="paths" style="white-space: pre-wrap; overflow-wrap: anywhere"></p>
  <script>
const pageURL = "https://example.com/shop/pages/catalog.html";
const examples = [...document.querySelectorAll("#examples a")];
document.querySelector("#paths").textContent = examples.map(link => {
  const path = link.getAttribute("href");
  return path + " → " + new URL(path, pageURL).href;
}).join("\n");
  </script>
</body>
</html>

စမ်းကြည့်ရင် ဘာဖြစ်မလဲ ./hours.html က /shop/pages/ ထဲ၊ ../images/product.svg က /shop/images/ ထဲမှာရှိတဲ့ URL အဖြစ် ထွက်ပါမယ်။

Root-relative Path နဲ့ URL အပြည့်အစုံ ဖတ်ခြင်း

အစမှာ / ပါရင် လက်ရှိ site ရဲ့ ထိပ်ဆုံးကနေ စပါတယ်။ URL အပြည့်အစုံမှာ protocol နဲ့ host ပါပြီး တခြား website ကိုလည်း ညွှန်းနိုင်ပါတယ်။

စမ်းသပ်နည်း ဒီနမူနာကို .html ဖိုင်အသစ်အဖြစ် သိမ်းပြီး browser နဲ့ ဖွင့်ပါ။ ပြင်ပြီးတိုင်း save နဲ့ reload လုပ်ပါ။

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Read root-relative and full URLs</title>
</head>
<body>
<p id="examples"><a href="/assets/logo.svg">Site logo</a> · <a href="https://static.example.org/logo.svg">External logo</a></p>
<p id="paths" style="white-space: pre-wrap; overflow-wrap: anywhere"></p>
  <script>
const pageURL = "https://example.com/shop/pages/catalog.html";
const examples = [...document.querySelectorAll("#examples a")];
document.querySelector("#paths").textContent = examples.map(link => {
  const path = link.getAttribute("href");
  return path + " → " + new URL(path, pageURL).href;
}).join("\n");
  </script>
</body>
</html>

စမ်းကြည့်ရင် ဘာဖြစ်မလဲ /assets/logo.svg က example.com ကို ဆက်သုံးပြီး URL အပြည့်က static.example.org ကို သုံးပါမယ်။

စာမျက်နှာသုံးခု ချိတ်ဆက်ခြင်း

Folder တစ်ခုထဲမှာ index.html၊ projects.html နဲ့ contact.html ရေးပါ။ တစ်မျက်နှာကနေ ကျန်နှစ်မျက်နှာကို သွားလို့ရအောင် ul ထဲမှာ link တွေ ထည့်ပါ။ projects.html ကို work folder ထဲ ရွှေ့ကြည့်ပါ။ အဝင် link ကို work/projects.html၊ အပြန်ကို ../index.html လို့ ပြင်ပြီး နှစ်ဖက်စလုံး စမ်းပါ။

တရားဝင် ကိုးကားချက်များ