php joomla- 如何从页面中删除不需要的 js 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10685152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
joomla- How to remove unwanted js files from page
提问by Hunter
joomla- How to remove unwanted js files from page
joomla- 如何从页面中删除不需要的 js 文件
I have used plugins some pages so many js files are included in all pages
我在某些页面上使用了插件,因此所有页面中都包含了许多 js 文件
回答by Kristian Hildebrandt
There are two ways that I am aware of:
我知道有两种方法:
1) get an instance if the document object and remove the js files (you could do that in a plugin) :
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) remove js files directly from your templates index.php :
2) 直接从模板 index.php 中删除 js 文件:
<?php unset($this->_scripts['/media/system/js/mootools-core.js']); ?>
回答by BadHorsie
If you want to remove all scripts that Joomla adds, including the inline script, the quickest way is this:
如果您想删除 Joomla 添加的所有脚本,包括内联脚本,最快的方法是:
$this->_script = $this->_scripts = array();
Add this anywhere in your template file above the <head>section.
将此<head>部分添加到模板文件中的任何位置。
回答by Ganesh Bora
You can simply edit these plugins code to remove these files. or uninstall these plugins if not required.
您可以简单地编辑这些插件代码来删除这些文件。或在不需要时卸载这些插件。
回答by Subrahmanyam
**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

