首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >相对路径,但是端口?

相对路径,但是端口?
EN

Stack Overflow用户
提问于 2011-11-30 04:09:55
回答 4查看 16.4K关注 1票数 24

我们都熟悉相对路径:从http://www.domain.com/hey链接到http://www.domain.com/hey/images/hello.jpg./images/hello.jpg的相对路径。

问题:当您在http://www.domain.com/hey时,如何声明http://www.domain.com:1234的相对路径

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-11-30 04:29:27

这可以通过设置window.location.port属性使用JavaScript来实现。

代码语言:javascript
复制
<a href="#" onclick="javascript:window.location.port=8080">go</a>
票数 22
EN

Stack Overflow用户

发布于 2011-11-30 05:00:26

您不能在相对URL中更改授权的任何部分(即host:port部分)。请参阅RFC 3986section 5.2.2中描述的算法,了解相对URL是如何解释的。需要注意的重要一点是,权限只是从基本URL或要解析的URL复制而来,而权限的结构永远不会被解释。这意味着您不能更改它的任何部分,包括端口部分。

下面是从RFC复制的伪代码中的算法

代码语言:javascript
复制
  -- The URI reference is parsed into the five URI components
  --
  (R.scheme, R.authority, R.path, R.query, R.fragment) = parse(R);

  -- A non-strict parser may ignore a scheme in the reference
  -- if it is identical to the base URI's scheme.
  --
  if ((not strict) and (R.scheme == Base.scheme)) then
     undefine(R.scheme);
  endif;

  if defined(R.scheme) then
     T.scheme    = R.scheme;
     T.authority = R.authority;
     T.path      = remove_dot_segments(R.path);
     T.query     = R.query;
  else
     if defined(R.authority) then
        T.authority = R.authority;
        T.path      = remove_dot_segments(R.path);
        T.query     = R.query;
     else
        if (R.path == "") then
           T.path = Base.path;
           if defined(R.query) then
              T.query = R.query;
           else
              T.query = Base.query;
           endif;
        else
           if (R.path starts-with "/") then
              T.path = remove_dot_segments(R.path);
           else
              T.path = merge(Base.path, R.path);
              T.path = remove_dot_segments(T.path);
           endif;
           T.query = R.query;
        endif;
        T.authority = Base.authority;
     endif;
     T.scheme = Base.scheme;
  endif;

  T.fragment = R.fragment;
票数 22
EN

Stack Overflow用户

发布于 2011-11-30 04:13:32

答案很简单:不可能是。如果主机发生更改,则需要使用绝对路径。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8317059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档