我们都熟悉相对路径:从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
的相对路径
发布于 2011-11-30 04:29:27
这可以通过设置window.location.port
属性使用JavaScript来实现。
<a href="#" onclick="javascript:window.location.port=8080">go</a>
发布于 2011-11-30 05:00:26
您不能在相对URL中更改授权的任何部分(即host:port部分)。请参阅RFC 3986的section 5.2.2中描述的算法,了解相对URL是如何解释的。需要注意的重要一点是,权限只是从基本URL或要解析的URL复制而来,而权限的结构永远不会被解释。这意味着您不能更改它的任何部分,包括端口部分。
下面是从RFC复制的伪代码中的算法
-- 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;
发布于 2011-11-30 04:13:32
答案很简单:不可能是。如果主机发生更改,则需要使用绝对路径。
https://stackoverflow.com/questions/8317059
复制相似问题