2014-10-19 73 views
1

我想包括一个自定义JS文件到我的joomla网站。我所做的就是编辑模板的index.php文件,然后在</head>之前加上<script src='custom.js"></script>。但是当页面被加载时,在我的自定义JS文件之后还有两个其他的JS文件被加载。我想通过在关闭头标记之前插入我的脚本加载行,我的JS文件应该是最后加载的。什么可能加载我的JS文件后,这2个JS文件,以及如何?如何确保自定义js文件加载最后在joomla

custom js inserted in index.php right before closing head tag

Yet some other JS files loaded after custom JS

回答

1

试试这个,

可以使用addCustomTag选项,这将不会加载你的头标记内JS文件,但它应该是最后的(从正在调用那里负载)

$stylelink .= '<link rel="stylesheet" href="../css/IEonly.css" />'; 
$document = JFactory::getDocument(); 
$document->addCustomTag($stylelink); 

欲了解更多details

希望工程..

0

有指定脚本的执行页面加载后(推迟)的选项。这是一个HTML特性,addScript()将其暴露在其接口中。文档:https://docs.joomla.org/JDocument/addScript

实施例:

$document = JFactory::getDocument(); 
$document->addScript('js/myscript.js', 'text/javascript', true);