2017-08-02 186 views
0

我刮在具有类似HTML相对路径与绝对file://协议

<a href="/pages/1></a> 网站

我也有window.location对象,在那里我有

origin:"http://www.example.org" 

所以我可以建立像绝对路径origin + href = http://www.example.org/pages/1

我做了我的文件页面的模型系统进行测试。

-www.example.org 
    |-2017 
    |-pages 
     |-1.html 
     |-2.html 
    |-2016 
    |-pages 
     |-1.html 
     |-2.html 
这些HTML

文件的链接是这个样子:

<!-- www.example.org/2016/pages/1.html --> <a href="../../2017/pages/1.html">2017</a>

在测试相同的代码将无法正常工作,因为window.location的对象的起源是file://

hash:"" 
host:"" 
hostname:"" 
href:"file:///home/me/projects/fp/src/test/fixtures/www.example.org/2016/pages/1.html" 
origin:"file://" 
pathname:"/home/me/projects/fp/src/test/fixtures/www.example.org/2016/pages/1.html" 
port:"" 
protocol:"file:" 

其中产生origin + href = file://../../2017/pages/1.html。如果协议是file:,对于一些字符串操作,我可以从location.pathname制作file:///home/me/projects/fp/src/test/fixtures/www.example.org/2017/pages/1.html。但是,解决这个问题是否正确?

+0

[File Uri Scheme和相关文件]的可能重复(https://stackoverflow.com/questions/7857416/file-uri-scheme-and-relative-files) – lazyvab

回答

1

file://只能用于绝对路径。

只有工作的相对路径是当前工作目录。