Get the full URI from the href property of a link

后端 未结 4 564
粉色の甜心
粉色の甜心 2020-12-13 14:07

I would like to have a confirmation on some point.

My goal is to always get the same string (which is the URI in my case) while reading the href property from a link

4条回答
  •  星月不相逢
    2020-12-13 14:47

    You could recompose the full url using a bit of javascript :

    function parseLink(link) {
        var baseUrl = location.href.substring(0,location.href.lastIndexOf('/'));
        if (link.indexOf('/') != -1) {
            link = link.substring(link.lastIndexOf('/')); 
        } else {
            link = "/"+ link;
        }
        var fullUrl = baseUrl + link;
        return fullUrl
    }
    

提交回复
热议问题