简体   繁体   English

Joomla 2.5在default.php中加载javaScript文件

[英]Joomla 2.5 Loading javaScript Files inside default.php

I was making a component in joomla 2.5 Which contains a default view.html and a tmpl/default.php as an layout file I need to add some javascript code into the default.php file and I added this Using the 我在joomla 2.5中制作了一个组件,该组件包含一个默认的view.html和一个tmpl / default.php作为布局文件,我需要在default.php文件中添加一些javascript代码,并使用

    $document->addScript(JURI::base() . "components/com_mycomp/javascript/myfile1.js");
    $document->addScript(JURI::base() . "components/com_mycomp/javascript/myfile11.js");
    $document->addScript(JURI::base() . "components/com_mycomp/javascript/myfile12.js");

it was working fine ( I tried it by adding a document.write() inside every js) , But the problem is I have a code inside my default.php inside 它工作正常(我通过在每个js内添加document.write()进行了尝试),但是问题是我的default.php内部有一个代码

   <script>window.jQuery || document.write('<script src="components/com_mycomp/myfile3.js"><\/script>');</script>

I tried to print it inside but nothing works so far... I also tried using the JURI::base. 我尝试在内部打印它,但到目前为止没有任何结果...我也尝试使用JURI :: base。 "path" inside php tags php标记内的“路径”

Am I doing It all wrong? 我做错了吗? How can I do it in joomla way Help and advices needed. 如何以joomla方式进行操作需要帮助和建议。

three's no need to add it using document.write . 三个不需要使用document.write添加它。 To import scrip file correctly, you can either do it using your first approach, or using the JHtml method like so: 要正确导入脚本文件,可以使用第一种方法,也可以使用JHtml方法,如下所示:

JHtml::_('script', 'components/com_mycomp/javascript/myfile1.js');
JHtml::_('script', 'components/com_mycomp/javascript/myfile11.js');
JHtml::_('script', 'components/com_mycomp/javascript/myfile12.js');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM