使用当前站点的相对路径保存书签

save bookmark with relative path to current-site

作为工作的一部分,同一个网络应用程序在不同单位的多个位置托管

例如

 http://site1.come/path-to-some-page
 http://site2.come/path-to-some-page

现在我将 site1 的书签另存为

 http://site1.come/path-to-some-page

但对于 site2,我将不得不再次创建一个新书签。我每周都要处理一个新的域名,每周一次又一次地做这个工作很痛苦。

我可以不保存相对于当前主机的书签吗

例如

 http://{CURRENT_HOST}/path-to-some-page

这会让我省去为每个新网站保存书签的痛苦

我还没有找到不借助小书签来保存亲戚或根亲戚的方法link。

就小书签而言,生成一个可以带您前往任何您喜欢的路径的小书签相对容易:

javascript:(rel=>{location=rel.startsWith('/')?`${location.protocol}//${location.host}${rel}`:`${location.protocol}//${location.host}${location.pathname}/${rel}`})('/path')

将末尾的 'path' 替换为包含您想要的任何路径的正确转义字符串。请注意,这将根据它们是否以 / 字符开头来区分相对路径和根相对路径。

长格式:

(rel => {
  location =
    // if the relative path starts with /
    rel.startsWith('/')
      // go to http(s)://{domain}/{relative path}
      ? `${location.protocol}//${location.host}${rel}`
      // otherwise go to http(s)://{domain}/{current path}/{relative path}
      : `${location.protocol}//${location.host}${location.pathname}/${rel}`
// call the function providing the relative path to use
})('/path')
javascript:void(window.location.href = '/path-to-some-page');

是另一种为相对路径添加书签的方法。