How to get base url with jquery or javascript?

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

    I was just on the same stage and this solution works for me

    In the view

    addScriptDeclaration('var base = \''.JURI::base().'\'');
        $document->addScript('components/com_name/js/filter.js');
    ?>
    

    In js file you access base as a variable for example in your scenario:

    console.log(base) // will print
    // http://www.example.com/
    // http://localhost/example
    // http://www.example.com/sub/example
    

    I do not remember where I take this information to give credit, if I find it I will edit the answer

提交回复
热议问题