How to get base url with jquery or javascript?

后端 未结 24 1363
忘掉有多难
忘掉有多难 2020-12-12 13:59

In joomla php there I can use $this->baseurl to get the base path, but I wanted to get the base path in jquery.

The base path may be any of the follo

24条回答
  •  一整个雨季
    2020-12-12 14:32

    This is not possible from javascript, because this is a server-side property. Javascript on the client cannot know where joomla is installed. The best option is to somehow include the value of $this->baseurl into the page javascript and then use this value (phpBaseUrl).

    You can then build the url like this:

    var loc = window.location;
    var baseUrl = loc.protocol + "//" + loc.hostname + (loc.port? ":"+loc.port : "") + "/" + phpBaseUrl;
    

提交回复
热议问题