0Day Forums
How to add javascript to joomla module? - Printable Version

+- 0Day Forums (https://zeroday.vip)
+-- Forum: Coding (https://zeroday.vip/Forum-Coding)
+--- Forum: CMS (https://zeroday.vip/Forum-CMS)
+---- Forum: Joomla (https://zeroday.vip/Forum-Joomla)
+---- Thread: How to add javascript to joomla module? (/Thread-How-to-add-javascript-to-joomla-module)



How to add javascript to joomla module? - ransome36 - 07-26-2023

Hi I have problem with adding javascript into a joomla module..I've found some solution, but it's not working..

$document = &JFactory::getDocument();
$document->addScript("/career.js");

These two lines I have in my module, but the script isn't in rendered site..
The file is in root of my web (for test purposes only).

Thanks for your help


RE: How to add javascript to joomla module? - joelynnbpdzizdgr - 07-27-2023

check the view source .

copy paste the path of the career.js as browser url and try to access it.

Change the path as needed.

. ./ ../


RE: How to add javascript to joomla module? - aborticide435 - 07-27-2023

You can Use following extension (works both 1.5 and 1.6) to include custom javascript or HTML easily.

[To see links please register here]


Also when you use directly may use full path like this (change the path of your .JS)

<?php
$document = &JFactory::getDocument();
$document->addScript( '/media/system/js/sample.js' );
?>


RE: How to add javascript to joomla module? - jaleesa915 - 07-27-2023

So only workaround which works for me is to add this js to template of my site..But its really awful solution, since I only need it in one article/module


RE: How to add javascript to joomla module? - jazznfmugilt - 07-27-2023

You could also use the joomla php module

[To see links please register here]

or maybe you found a module that better fits your needs at:

[To see links please register here]




RE: How to add javascript to joomla module? - cadaver473 - 07-27-2023

Ouch..The main problem is, that I am loading the page containing custom module with javascript is loaded via ajax..And all the plugins seems to be adding the js code into head and I only replace some elements into body of my page.
exist some solution to this problem?I know I can have all the js logic into one file, but I am not sure it is good way. Is somehow possible to include js directly to module?So that the script tag will be within my document body and correctly included (i am not sure the code will be fired??)

Thanks


RE: How to add javascript to joomla module? - trennaqbtxxqjkr - 07-27-2023

Try this, it's working perfectly.

$document = &JFactory::getDocument();
$document->addScript('modules'.DS.'MOD_YOURMODULENAME'.DS.'javascript.js');



RE: How to add javascript to joomla module? - hexylresorcinol936415 - 07-27-2023

Make sure that you have this

<jdoc:include type="head" />

after head tag in template index.php


RE: How to add javascript to joomla module? - forsakenly534266 - 07-27-2023

For all those who are landing on this page at a much later date, and looking for solution in Joomla 3.x

You can include a module of type "Custom HTML Advanced" which will NOT filter out any script or style tags.
You can use it on any of the pages you want.

Hope this helps you :)