joomla-如何从页面中删除不需要的js文件

Hun*_*ter 14 php joomla

joomla-如何从页面中删除不需要的js文件

我在插件中使用了一些页面,因此所有页面都包含了很多js文件

Kri*_*ndt 24

我知道有两种方法:

1)获取一个实例,如果文档对象并删除js文件(你可以在插件中执行):

<?php 
         //get the array containing all the script declarations
         $document = JFactory::getDocument(); 
         $headData = $document->getHeadData();
         $scripts = $headData['scripts'];

         //remove your script, i.e. mootools
         unset($scripts['/media/system/js/mootools-core.js']);
         unset($scripts['/media/system/js/mootools-more.js']);
         $headData['scripts'] = $scripts;
         $document->setHeadData($headData);
?>
Run Code Online (Sandbox Code Playgroud)

2)直接从模板index.php中删除js文件:

<?php unset($this->_scripts['/media/system/js/mootools-core.js']); ?>
Run Code Online (Sandbox Code Playgroud)


Bad*_*sie 5

如果要删除Joomla添加的所有脚本,包括内联脚本,最快的方法是:

$this->_script = $this->_scripts = array();
Run Code Online (Sandbox Code Playgroud)

在该<head>部分上方的模板文件中的任何位置添加它.