how to get the base url in javascript

前端 未结 10 1847
一整个雨季
一整个雨季 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:57

    To get exactly the same thing as base_url of codeigniter, you can do:

    var base_url = window.location.origin + '/' + window.location.pathname.split ('/') [1] + '/';
    

    this will be more useful if you work on pure Javascript file.

提交回复
热议问题