2012-12-07 85 views
5

Joomla 2.5中,以下脚本会自动加载。在Joomla 2.5中停止加载自动脚本

<script src="/media/system/js/mootools-core.js" type="text/javascript"></script> 
<script src="/media/system/js/core.js" type="text/javascript"></script> 
<script src="/media/system/js/caption.js" type="text/javascript"></script> 
<script src="/media/system/js/mootools-more.js" type="text/javascript"></script> 
<script src="/templates/pswedge/js/jquery.min.js" type="text/javascript" defer="defer"></script> 

我不想加载这些文件。我如何删除这些链接?

+0

你使用哪种模板或任何自由模板? – Toretto

+1

我自己构建了模板。其实我需要知道的代码在哪里生成 –

+0

然后检查你的模板头部分,那些脚本插入它那里注释掉。 – Toretto

回答

8

我不建议你改变Joomla.But的核心文件,如果你真的需要到,那么你可以试试这个:

步骤来禁用Joomla模板预装的脚本文件。

步骤一:使用您喜欢的文件编辑器,打开要编辑:

/libraries/joomla/document/html/renderer/head.php

步骤一:找到这段代码在线151和更新,以包括与此代码:

// Generate script file links 
foreach ($document->_scripts as $strSrc => $strAttr) 
{ 
    // Code to disable mootools for your site (still loads it for your admin) 

    $ex_src = explode("/",$strSrc); 
    $js_file_name = $ex_src[count($ex_src)-1]; 
    $js_to_ignore = array("mootools-core.js","mootools-more.js","core.js","caption.js"); 
    if(in_array($js_file_name,$js_to_ignore) AND substr_count($document->baseurl,"/administrator") < 1 AND $_GET['view'] != 'form') 
     continue; 

    $buffer .= $tab . '<script src="' . $strSrc . '"'; 
    if (!is_null($strAttr['mime'])) 
    { 
     $buffer .= ' type="' . $strAttr['mime'] . '"'; 
    } 
    if ($strAttr['defer']) 
    { 
     $buffer .= ' defer="defer"'; 
    } 
    if ($strAttr['async']) 
    { 
     $buffer .= ' async="async"'; 
    } 
    $buffer .= '</script>' . $lnEnd; 
} 

保存更改后上面,清除您设置的缓存并测试您的Joomla网站和您的Joomla管理仪表板。如果您查看源代码,则所有预定义文件都不存在。

或者

你可以尝试这样从index.php把它藏在模板。只需将该行放在<jdoc:include type="head" />之前,并根据需要对脚本进行必要的更改。

<?php 
    $search = array('mootools-more.js', 'caption.js'); 
    // remove the js files 
    foreach($this->_scripts as $key => $script) { 
     foreach($search as $findme) { 
      if(stristr($key, $findme) !== false) { 
       unset($this->_scripts[$key]); 
      } 
     } 
    } 
?> 
3

可以将这些方法的工作 -

方法1一个: 把以前<jdoc:include type="head" />

$search = array('mootools', 'caption.js'); 
    // remove the js files 
    foreach($this->_scripts as $key => $script) { 
     foreach($search as $findme) { 
      if(stristr($key, $findme) !== false) { 
       unset($this->_scripts[$key]); 
      } 
     } 
    } 

//方法2

中的index.php模板

$parameter_script = 'scripts'; 
$headerstuff=$document->getHeadData(); 
reset($headerstuff[$parameter_script]); 
foreach($headerstuff[$parameter_script] as $key=>$value){ 
unset($headerstuff[$parameter_script][$key]);  
} 
$document->setHeadData($headerstuff); 

//方法3

在文件目录/plugins/system创建一个名为“removemootools.php”新的文件,并插入下面的代码(你需要注册插件在数据库中,也是如此)。

class plgSystemRemoveMooTools extends JPlugin 
{ 
public function onAfterDispatch() 
{ 
$app = JFactory::getApplication(); 
if($app->isSite()) //Only ever remove MooTools from the client-side, never the admin side 
{ 
//Repeat these three line for all js you want to exclude 
$mootools = JURI::root(true).DS.'media'.DS.'system'.DS.'js'.DS.'mootools.js'; 
$document = JFactory::getDocument(); 
unset($document->_scripts[$mootools]); 
} 
} 
} 
0

我用这段代码从头部删除jquery文件(Joomla!3.3。1)

<?php 

//Remove jquery 
$search = array('jquery', 'jquery.min.js'); 
    // remove the js files 
    foreach($this->_scripts as $key => $script) { 
     foreach($search as $findme) { 
      if(stristr($key, $findme) !== false) { 
       unset($this->_scripts[$key]); 
      } 
     } 
    } 
?> 

<jdoc:include type="head" /> 
0

有两种方法,我知道的:

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