私はまた、私はそう相対パス://プロトコル
origin:"http://www.example.org"
を持ってwindow.location
オブジェクトを、持っている同様のHTML
<a href="/pages/1></a>
を持つサイトでこするん私は絶対パスを構築することができますorigin + href
= http://www.example.org/pages/1
私は私のファイルにページのモックアップを作りましたテスト用のシステム。 window.locationのオブジェクトの原点がfile://
あるので、同じコードが動作しませんテストで
<!-- www.example.org/2016/pages/1.html --> <a href="../../2017/pages/1.html">2017</a>
:これらのhtmlで
-www.example.org
|-2017
|-pages
|-1.html
|-2.html
|-2016
|-pages
|-1.html
|-2.html
リンクは次のようになりファイル
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:
なら、file:///home/me/projects/fp/src/test/fixtures/www.example.org/2017/pages/1.html
をlocation.pathname
から作ることができました。しかし、この問題を処理するのは正しい方法ですか?
[ファイルUriスキームと相対ファイル](https://stackoverflow.com/questions/7857416/file-uri-scheme-and-relative-files)の可能な複製 – lazyvab