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

时间:2012-05-21 12:19:51

标签: php joomla

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

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

4 个答案:

答案 0 :(得分: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']); ?>

答案 1 :(得分:5)

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

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

<head>部分上方的模板文件中的任意位置添加此内容。

答案 2 :(得分:0)

您只需编辑这些插件代码即可删除这些文件。或者如果不需要,请卸载这些插件。

答案 3 :(得分:-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