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
$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
<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. "path" inside php tags
Am I doing It all wrong? How can I do it in joomla way Help and advices needed.
three's no need to add it using document.write
. To import scrip file correctly, you can either do it using your first approach, or using the JHtml
method like so:
JHtml::_('script', 'components/com_mycomp/javascript/myfile1.js');
JHtml::_('script', 'components/com_mycomp/javascript/myfile11.js');
JHtml::_('script', 'components/com_mycomp/javascript/myfile12.js');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.