浏览器直接打开本地html文件所使用的协议
file://
协议的作用- 表示浏览器直接从本地文件系统加载文件(而非通过网络请求)。
- 路径格式:
- Windows:
file:///C:/path/to/file.html
(注意三个斜杠) - macOS/Linux:
file:///Users/name/file.html
- Windows:
- 与网络协议的区别
协议 | 用途 | 示例 |
---|---|---|
file:// | 访问本地文件 | file:///C:/test.html |
http:// | 通过 HTTP 访问网络资源 | http://example.com |
https:// | 通过加密 HTTPS 访问网络 | https://example.com |
为什么不是 http://
或 https://
?
- 这些协议需要服务器(如 Apache、Nginx)托管文件,而本地直接打开文件时无需服务器。