How to get base url with jquery or javascript?

后端 未结 24 1438
忘掉有多难
忘掉有多难 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:41

    I've run into this need on several Joomla project. The simplest way I've found to address is to add a hidden input field to my template:

    
    

    When I need the value in JavaScript:

    var baseurl = document.getElementById('baseurl').value;
    

    Not as fancy as using pure JavaScript but simple and gets the job done.

提交回复
热议问题