admin管理员组文章数量:1290978
I have created a template in Joomla! 3x, but I want to remove the default JavaScript code and stylesheets in the page header.
My code is:
$doc = JFactory::getDocument();
//Remove default configuration
$doc->setGenerator("");
$headData = $doc -> getHeadData();
unset($headData['metaTags']['http-equiv']);
$doc -> setHeadData($headData); //Is OK
$doc -> _styleSheets = array(); //Is OK
$doc -> _scripts = array(); //Is OK
$doc -> _script = array(); **// Not OK**
//Add foundation
$doc->addStyleSheet('templates/'.$this->template.'/css/foundation.css');
$doc->addScript('templates/'.$this->template.'/js/jquery.js');
$doc->addScript('templates/'.$this->template.'/js/modernizr.foundation.js');
The template header HTML is now:
function keepAlive() { var myAjax = new Request({method: "get", url: "index.php"}).send();} window.addEvent("domready", function(){ keepAlive.periodical(840000); });
jQuery(document).ready(function() {
jQuery('.hasTooltip').tooltip({});
});
// The block is not removed
How do I remove this JavaScript code?
Reference files:
- /libraries/joomla/html/behavior.php
- /libraries/cms/html/bootstrap.php
I have created a template in Joomla! 3x, but I want to remove the default JavaScript code and stylesheets in the page header.
My code is:
$doc = JFactory::getDocument();
//Remove default configuration
$doc->setGenerator("");
$headData = $doc -> getHeadData();
unset($headData['metaTags']['http-equiv']);
$doc -> setHeadData($headData); //Is OK
$doc -> _styleSheets = array(); //Is OK
$doc -> _scripts = array(); //Is OK
$doc -> _script = array(); **// Not OK**
//Add foundation
$doc->addStyleSheet('templates/'.$this->template.'/css/foundation.css');
$doc->addScript('templates/'.$this->template.'/js/jquery.js');
$doc->addScript('templates/'.$this->template.'/js/modernizr.foundation.js');
The template header HTML is now:
function keepAlive() { var myAjax = new Request({method: "get", url: "index.php"}).send();} window.addEvent("domready", function(){ keepAlive.periodical(840000); });
jQuery(document).ready(function() {
jQuery('.hasTooltip').tooltip({});
});
// The block is not removed
How do I remove this JavaScript code?
Reference files:
- /libraries/joomla/html/behavior.php
- /libraries/cms/html/bootstrap.php
2 Answers
Reset to default 6I found a simple solution here and here:
unset($this->_scripts[JURI::root(true).'/media/system/js/caption.js']);
or
unset ( $this -> _metaTags[ 'http-equiv' ] ) ;
$this -> _scripts = array ( ) ;
$this -> _script = array ( ) ;
to get the whole lot. :)
Do not use:
$doc -> setHeadData($headData);
It does weird and mysterious things.
The problem that you (and I) were having is resetting the $doc
variable through $doc->setHeadData($headData)
instead of unsetting the _scripts
and _script
through $this
. Coderwall. provides a thorough example.
Use JHtml::_('behavior.disable','behavior');
to remove specific behavior
We have so many posts on the web and forums where users are asking to remove this or that behavior. Instead of them hacking their way trough the views and core we could have:
JHtml::_('behavior.disable','specific behavior'); to remove the ones we don't want
Example scenario
Tooltips are loaded no matter if your HTML overrides are not loading it.
JHtml::_('behavior.disable','tooltips');
placed in template index.php
could do
this for you and this way help you clean your head tag from unwanted scripts.
In 3.0 if you just want to remove tooltips from registration you have to copy the view to HTML override. Remove JHtml::_('behavior.tooltip'); from the file and then it is gone. I think that this should be done without HTML overrides.
And in 2.5.x even using HTML overrides does not help. Tooltip stays.
If any other extension that you have installed is loading behavior that you don't want, it will take you longer to figure out where it is.
本文标签: jqueryHow to remove JavaScript code in the template header (Joomla 30x)Stack Overflow
版权声明:本文标题:jquery - How to remove JavaScript code in the template header (Joomla! 3.0.x)? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741521163a2383192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论