假设我在
http://sub.example.org/path/index.htm
如何
<a href="">Link</a>
行看看它是否应该做的只是将协议(protocol)更改为 https:
https://sub.example.org/path/index.htm
不需要知道页面所在的当前 URL (sub.example.org/path/index.htm
),所以是相对的?
示例用例:提供“从现在开始使用安全连接 (HTTPS/TLS)!”所有页面上的链接。
最佳答案
您无法使用相对 URI 实现此目的。相对 URI 总是从某个点开始,然后将一切更改到该点的右侧。
您可以使用服务器端代码或 JavaScript 计算 URL:
location = location.toString().replace(/^http:/, "https:");
关于html - 如果只更改当前 URL 的协议(protocol),相对 href 链接看起来如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23580426/