14

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

我已经使用插件一些页面所以所有页面中都包含很多js文件

4

4 回答 4

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);
?>

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

<?php unset($this->_scripts['/media/system/js/mootools-core.js']); ?>
于 2012-05-22T03:48:47.230 回答
5

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

$this->_script = $this->_scripts = array();

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

于 2014-05-21T13:40:55.880 回答
0

您可以简单地编辑这些插件代码以删除这些文件。或在不需要时卸载这些插件。

于 2012-05-21T12:21:30.607 回答
-7
**An easiest way to disable mootools/ unwanted javascripts for your site in joomla cms ( 2.5 version )**(still loads it for your admin)


**Step-1:** 
Using your favorite file editor, open for edit:
libraries/joomla/document/html/renderer/head.php

**Step-2:** check for code in head.php

// Generate script file links
foreach ($document->_scripts as $strSrc => $strAttr)
{
// *** start *** //
$ex_src = explode("/",$strSrc);
$js_file_name = $ex_src[count($ex_src)-1];
$js_to_ignore = array("mootools-more.js","core.js"); // scripts to skip loading
//skip loading scripts..
if( in_array($js_file_name,$js_to_ignore) AND substr_count($document->baseurl,"/administrator") < 1 AND $_GET['view'] != 'form'){continue;}
// *** end *** //


**Step-3:** 
Clear cache & refresh page.


it works for sure.

For detailed explanation : http://www.inmotionhosting.com/support/edu/joomla-25/302-disable-mootools-in-joomla-25
于 2013-01-09T06:42:37.330 回答