8
votes
Accepted
how to display message in joomla using javascript
It expects the messages to be passed in an array, even if there is only a single message, ie
Joomla.renderMessages({"success":["this is test message"]});
The formatting example given in the source ...
8
votes
Accepted
Control order of loaded scripts
The JDocument's addScript method has no options for ordering (eg by priority or something like WP).
There are numerous ways to solve your problem.
First, to understand why what you're doing is ...
7
votes
Accepted
Add script just after <head>
First, according to the docs AdSense code doesn't go after the <head>, it goes between the <body> tags. JavaScript should almost always be placed at the end of the body, just before </...
5
votes
Accepted
How to use HTMLHelper to add to the document head
1) JHtml is an alias for Joomla\CMS\HTML\HTMLHelper class. You'll have to start using the real class sooner or later because the alias will not exist in Joomla! 5.0. To use the real class you have to ...
5
votes
Accepted
Best Practice: Loading component Styles & Scripts in J4
Both have pros and cons.
Web Asset Manager is great if your loading an asset that depends on another one. For example:
some jQuery plugin
that depends on jQuery
Your json file can set jQuery as a ...
5
votes
Accepted
Can I delay loading a css file until a user is logged in?
Very interesting and good question in my opinion.
For this task I would use the 'joomla_user_state' cookie which is available from your template index.php file. (otherwise you can do this form a ...
4
votes
How can I insert js scripts before </body>
I think there are at least 4 options.
In gantry5 templates go extension>templates, select your template, and on the page settings tab there is a textbox labeled "Before </body>". This will be ...
4
votes
Accepted
How to overwrite a module's .php to control what scripts it adds to the head of the doc?
module_name.php file can't be overridden.
Check to see if the module has options to disable the loading of its scripts - Many modules come with such settings.
If it hasn't, then you could propose ...
4
votes
Accepted
Joomla site overrides Array.from() causing Google Maps JavaScript API v3 to not work correctly
I had the same issue - Google Maps doesn't like the combination of Mootools (enabled in my Template) and Progressive Cache (enabled in Joomla Global Config)
Luckily, I could disable Mootools in my ...
4
votes
Accepted
How can I add a local custom javascript file into the bottom of the template's index.php file?
Unfortunately Casseopeia (default Joomla 4 frontend template) uses the following:
<jdoc:include type="scripts" />
inside the <head> tags at the top of the DOM, so any script ...
4
votes
Accepted
How to add a piece of JavaScript code to the header?
Find your templates index.php file: [httpdocs]/templates/[YOURTEMPLATE]/index.php
In the index.php file, find the <head> tag and add your snippet there using <script> tags.
Example
<...
4
votes
How to Fix PHP Deprecated : Factory::getDocument() is deprecated
Use Joomla\CMS\Application\WebApplication::getDocument(). In your code you're already doing this with $app->getDocument().
4
votes
JRequest Method in Joomla 4
Use Joomla\Input\Input class. Instance relevant to the current request can be accessed through the application:
use Joomla\CMS\Factory;
$controller->execute(Factory::getApplication()->getInput()...
3
votes
how to display message in joomla using javascript
The above answer is great, below is some code to add a title to the message. As a side note, you can also load other strings & use those to create a custom alert. The title of the string is added ...
3
votes
What's the correct way of adding code after the start of the body tag?
If you don't want to edit the template's index.php file, then I'd suggest that you use a plugin and utilise JApplication to get and set the body.
You can then use the following in your plugin:
...
3
votes
Accepted
What's the correct way of adding code after the start of the body tag?
Complementing the answer from @veritas399, you could also use a third party extension such as EasyScript or similar to insert the code into your web page without worrying about future template or ...
3
votes
How do I add "id" to script declaration
JDocument has a method for inserting arbitrary characters into the head tag. People usually use it for meta tags etc. It's down the bottom of this page:
https://docs.joomla.org/J3.x:...
3
votes
Accepted
Placing inline javascript into the head tags of one page only
I love Regular Labs Sourcerer and use it on quite a few websites but if you only want to add code into the header area of a specific page, the easiest way to do this is to use the HeadTag plugin (free)...
3
votes
"0 Class 'JToolbarHelper' not found" error while trying to login to the backend
I was able to solve the issue thanks to the help from github.
Add following code to the /sitefolder/administrator/includes/helper.php:
if(!class_exists('JToolbarHelper')) {
require_once ...
3
votes
Accepted
How to include scripts in <head>
Default Joomla behaviour is to add scripts to the head element.
Try looking where <jdoc:include type="head" /> appears in your template (under template/YOURTEMPLATE/index.php) - it may have ...
3
votes
Accepted
How to check JSESSION in javascript
One way I can imagine to check the session is before you ignite the above ajax call, you make a previous ajax call to another function in com_contract/controller(task = your new session checking ...
3
votes
Accepted
Client side validation - custom event handler not called when user enters the field and leaves it being empty
I deleted my earlier answer, since it was on some points true but not exactly answered the question. My mind was blurred by the question. :) The question is very tricky. Why?
Because in the question ...
3
votes
Accepted
iFrame with javascript
Firstly, your Javascript contains an error so it won't run at all. Specifically you're missing a ) near the end.
Secondly, Google send a X-Frame-Options: SAMEORIGIN header, basically meaning you ...
3
votes
Link to Page & Pre-Filter Portfolio Items
By "anchor and jquery" you mean like the way bootstrap tabs work - ie. by letting the uri's fragment hit the id of the tab. But these tabs aren't set up like that. You can of course use jquery to ...
3
votes
Accepted
Link to Page & Pre-Filter Portfolio Items
I found the answer, thanks for the help @jamesgarrett
The tabs were using shuffle.js so I needed to edit the page builder js file.
jQuery(function($) {
var $container = $('.sp-simpleportfolio-...
3
votes
Accepted
Send error or exception returned from ajax request to enqueuemessage
When you say "display it into enqueuemessage" I'm assuming that you want to display it in the same message area that enqueueMessage displays in. You can do that in your javascript by calling Joomla....
3
votes
Accepted
How to show multidimensional data in my CanvasJS chart?
Your original coding attempt is repeatedly overwriting the $dataPoints variable inside of the loop -- this is why you only see the last iteration's data.
To create the desired multidimensional array ...
3
votes
Accepted
How is Mootools loaded?
In Joomla it's possible to load JavaScript libraries via different ways, via:
your template
a component
a (system) plugin
a module
When it's loaded on every page, it's usually loaded via your ...
3
votes
How to add a piece of JavaScript code to the header?
In addition to the good answer by @Guitarman that specifically explains how to add script to the header in a single website's template, which is what the OP is asking for, there are other approaches ...
3
votes
Accepted
Joomla 4 - Cassiopeia add JS and CSS
The old method to add stylesheets and scripts to the doc head was to use the HTMLHelper. An good explanation how to use that: https://rolandd.com/blog/joomla/adding-stylesheets-scripts-and-images
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
javascript × 251joomla-3.x × 107
php × 47
jquery × 47
css × 23
joomla-4.x × 18
ajax × 17
joomla-2.5 × 12
module × 12
plugin × 12
joomla-3.4 × 10
component × 9
extensions × 9
templates × 7
joomla-3.3.x × 7
rsform × 7
joomla-4 × 7
jdocument × 7
development × 6
jform × 6
bootstrap × 6
mysql × 5
custom-component × 5
joomla-api × 5
virtuemart × 5