joining relative urls?

Posted by heffaklump on Stack Overflow See other posts from Stack Overflow or by heffaklump
Published on 2010-04-20T15:01:04Z Indexed on 2010/04/20 15:03 UTC
Read the original article Hit count: 274

Filed under:

So i want to join strings with relative urls in Javascript.

base url = "http://www.adress.com/more/evenmore"

with

relative url = "../../adress" => "http://www.adress.com/adress"
relative url = "../adress" => "http://www.adress.com/more/adress"

What would be the best way? I was thinking of using regexp and checking
how many "../" i find, then subtracting that amount from the baseurl and adding them to what is left.

© Stack Overflow or respective owner

Related posts about JavaScript