how to get the base url in javascript

前端 未结 10 1824
一整个雨季
一整个雨季 2020-12-01 04:12

I am building a website with CodeIgniter, I have various resources that I load with the base_url helper function like this

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 04:55

    This is done simply by doing this variable.

    var base_url = ''
    

    This will have base url now. And now make a javascript function that will use this variable

    function base_url(string){
        return base_url + string;
    }
    

    And now this will always use the correct path.

    var path    =   "assets/css/themes/" + color_ + ".css"
    $('#style_color').attr("href", base_url(path) );
    

提交回复
热议问题