2012-12-07 62 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']); ?>