Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用file://协议到绝对值的相对路径_Javascript_Html_Path - Fatal编程技术网

Javascript 使用file://协议到绝对值的相对路径

Javascript 使用file://协议到绝对值的相对路径,javascript,html,path,Javascript,Html,Path,我在一个有类似html的网站上进行抓取 我还有窗口。location对象 origin:"http://www.example.org" 因此,我可以构建绝对路径,如origin+href= 我在我的文件系统上制作了一个页面模型以进行测试 -www.example.org |-2017 |-pages |-1.html |-2.html |-2016 |-pages |-1.html |-2.html 在这些html

我在一个有类似html的网站上进行抓取


我还有
窗口。location
对象

origin:"http://www.example.org"
因此,我可以构建绝对路径,如
origin+href
=

我在我的文件系统上制作了一个页面模型以进行测试

-www.example.org
  |-2017
    |-pages
      |-1.html
      |-2.html
  |-2016
    |-pages
      |-1.html
      |-2.html
在这些html文件中,链接如下所示:


在测试中,相同的代码不起作用,因为window.location对象的原点是
文件://

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:///home/me/projects/fp/src/test/fixtures/www.example.org/2017/pages/1.html
来自
位置.路径名
如果协议是
文件:
。但这是处理此问题的正确方法吗?

文件://
只能用于绝对路径

唯一有效的相对路径是当前工作目录。

可能的副本