如何在joomla 3.8中包含外部js文件

问题描述 投票:0回答:1

如何在joomla 3.8中包含不同文章和模块中的外部js文件。

提前致谢..!

php joomla3.0
1个回答
1
投票

使用Joomla API包含JavaScript文件有两种方法。第一种是使用addScript方法的JDocument类:

 <?php
    $document = JFactory::getDocument();
    $document->addScript('/media/system/js/sample.js');
    ?>

2-第二个使用脚本方法的JHTML类

<?php
// Add the path parameter if the path is different than 'media/system/js/'
JHTML::script('sample.js', 'templates/custom/js/');
?>

API在3.x中已更改,因此第二个参数不能是字符串。如果您确实需要使用此方法,则必须包含JavaScript文件的绝对链接:

<?php
JHtml::script(Juri::base() . 'templates/custom/js/sample.js');
?>

希望这能帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.