创建另一个端口中文件的HTML链接?

Mai*_*tor 7 html html5

下面的标记会停止指向页面的链接,而无需提供完整的URL:

<a href="foo.html">link</a>
Run Code Online (Sandbox Code Playgroud)

所以,如果你点击它example.com/,你会去example.com/foo.html.有没有办法创建一个链接,example.com:port/foo.html而不是去?

Phi*_*ide 1

请参阅此处 -> /sf/answers/421145301/

// delegate event for performance,
// and save attaching a million events to each anchor
document.addEventListener('click', function(event) {
  var target = event.target;
  if (target.tagName.toLowerCase() == 'a')
  {
      var port = target.getAttribute('href')
                       .match(/^:(\d+)$/);
      if (port)
      {
         target.port = port[1];
      }
  }
}, false);
Run Code Online (Sandbox Code Playgroud)

似乎是最好的方法。我认为纯粹的 HTML 解决方案是不可能的。