Relative URLs in AJAX requests

后端 未结 2 1923
感情败类
感情败类 2020-11-27 14:29

Why does Javascript treat relative URLs differently than standard HTML? Think of the following URL (or just browse to it): http://en.wikipedia.org/wiki/Rome. Open a Firebug

2条回答
  •  日久生厌
    2020-11-27 14:52

    Looks like http://code.google.com/p/js-uri/ is the library of choice for URL manipulation in general and this type of absolute-to-relative computation in particular:

    new URI(potentiallyRelativeLink).resolve(new URI(window.location.href)).toString()
    

提交回复
热议问题