Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在joomla 3.8中包含外部js文件_Php_Joomla3.0 - Fatal编程技术网

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

Php 如何在joomla 3.8中包含外部js文件,php,joomla3.0,Php,Joomla3.0,如何在不同的文章和模块中包含joomla 3.8中的外部js文件 提前谢谢 有两种方法可以使用Joomla API包含JavaScript文件。第一个是使用addScript方法的JDocument类: <?php $document = JFactory::getDocument(); $document->addScript('/media/system/js/sample.js'); ?> 2- 第二个使用script方法的JHTML类 &

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


提前谢谢

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

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

2- 第二个使用script方法的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');
?>


希望这对你有帮助

感谢您的时间,Mohammed,您能告诉我我们需要在哪个文件中添加此代码吗?但我认为在您的情况下,您需要在模块中导入,因此,有三种方法可以使用Joomla API将JavaScript嵌入到您的代码中:JDocument::addScriptDeclaration、JDocument::addScript和script。这些方法必须在组件视图/views//view.html.php中调用,或者通过模板脚本/views//tmpl/.php调用,或者如果是模块,则在其模板脚本/tmpl/.php中调用。谢谢Mohammed如果对您有帮助,您可以查看我的答案吗?请查看我的答案。但是还有一种方法可以添加外部js文件。在添加文章时,我们可以在代码编辑器本身中提供addexternaljs文件,我在该编辑器中使用jck编辑器,我们必须通过允许外部js文件来更改配置设置。