Module
Contents
Index 🔎︎

# 相对和绝对链接

插入超链接时，必须考虑两个因素：保存时将超链接设置为相对还是绝对，以及文件是否存在。

- 如果 LibreOffice 创建 相对或绝对超链接，请选择 LibreOffice - 首选项工具 - 选项
  - 加载/保存 - 常规，并指定保存相对 URL 地址 字段。只有在您当前使用的文档和链接目标位于同一驱动器时，才可使用相对链接。

- You should create the same directory structure on your hard disk as that which exists in the web space hosted by your Internet provider. Call the root directory for the homepage on your hard disk "homepage", for example. The start file is then "index.html", the full path being "C:\homepage\index.html" (assuming Windows operating system). The URL on your Internet provider's server might then be as follows: "http://www.myprovider.com/mypage/index.html". With relative addressing, you indicate the link relative to the location of the output document. For example, if you placed all the graphics for your homepage in a subfolder called "C:\homepage\images", you would need to give the following path to access the graphic "picture.gif": "images\picture.gif". This is the relative path, starting from the location of the file "index.html". On the provider's server, you would place the picture in the folder "mypage/images". When you transfer the document "index.html" to the provider's server through the File - Save As dialog, and if you have marked the option Copy local images to Internet under LibreOffice - Preferences Tools - Options
  - Load/Save - HTML Compatibility, LibreOffice will automatically copy the graphic to the correct directory on the server.

- An absolute path such as "C:\homepage\graphics\picture.gif" would no longer function on the provider server. Neither a server nor the computer of a reader needs to have a C hard drive: operating systems such as Unix or macOS do not recognize drive letters, and even if the folder homepage\graphics existed, your picture would not be available. It is better to use relative addressing for file links.

- Web 页的链接，例如 "www.example.com" 或 "www.myprovider.com/mypage/index.html" 是一个绝对链接。

- LibreOffice 会根据链接中引用的文件是否存在以及存在于何处而做出不同的响应。LibreOffice 检查每个新链接并自动设置目标和协议。结果可以在保存源文档后生成的 HTML 代码中看到。

- 有下列规则：一个相对地址("graphics/picture.gif")只有当两个文件存放在同一个驱动盘上时才能采用。如果两个文件存放在不同的驱动盘上，但在本机文件系统中，那么要采用一个符合"file:"协议 ("file:///data1/xyz/picture.gif")的绝对地址。如果两个文件存放在不同的服务器上，或是当前超链接的目标不存在，那么要采用一个符合"http:"协议("http://data2/abc/picture.gif")的绝对地址。

- 确保主页用到的所有文件都与主页的起始文件在同一驱动器上。这样，LibreOffice 就可以设置协议和目标，以使服务器上的引用始终正确。

在一个超链接的帮助提示中和在HTML源文本编辑器中，您总是看到绝对表达法，这是因为LibreOffice在内部总是用绝对路径工作的。输出成HTML时会向文件中写些什么，只有当您亲自查看了输出成HTML的结果后才能知道，例如您把已生成的HTML文件当作"文本"装入或用一个文本编辑器打开时。

相关主题

编辑超链接