[HTML] Absolute href vs relative href

An absolute URL - points to another web site (like href="http://www.example.com/default.htm")

A relative URL - points to a file within a web site (like href="default.htm")

When you have a <a href="./a/1.html">W3Schools</a>-- this is a relative URL, assume we are currently on this page: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_a_href

you can open devtool seeing that:

 

Browser will convert a hrefto a absolute url for sure.

 

Rules:

Relative path: 

Given: https://www.example.com/a/b/c/1.html 
href: ./2.html
Result: https://www.example.com/a/b/c/2.html

Given: https://www.example.com/a/b/c/1.html 
href: ../2.html
Result: https://www.example.com/a/b/2.html

Given: https://www.example.com/a/b/c/1.html 
href: ../../d/2.html
Result: https://www.example.com/a/d/2.html

 

Absolute path:

Given: https://www.example.com/a/b/c/1.html 
href: /js/app-zwan123.js
Result: https://www.example.com/js/app-zwan123.js

 

posted @   Zhentiw  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2024-02-06 [Go] Unit testing Go code
2024-02-06 [Go] Go routines with WaitGroup and async call
2024-02-06 [ Go] GoRoutines and Channels
2024-02-06 [Go - slice] Remove Elements from a slice in Go
2024-02-06 [Go] defer & recover
2024-02-06 [Go] Defer keyword
2023-02-06 [Typescript] Global Scope
点击右上角即可分享
微信分享提示