Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if jQuery is included in Header (Joomla)

Is there a way to check if jQuery is loaded using PHP?

I have two different plugins in Joomla that load the jQuery JS, but when it is included more than once it does not work correctly.

To explain the process a bit more: Joomla offers an ability to intercept the HTML source before it is rendered, essentially working on the source code itself.

This is using the function:

onPrepareContent(&$row, &$params, $limitstart)

$row is the HTML content of the page that can be parsed.

I was thinking that maybe a preg_match could work but don't have very much experience with it.

like image 248
privateace Avatar asked Aug 26 '09 01:08

privateace


1 Answers

Better yet, you can verify it with JavaScript and then add it to the head if missing.

   if (typeof jQuery == 'undefined') { 
   var head = document.getElementsByTagName("head")[0];
   script = document.createElement('script');
   script.id = 'jQuery';
   script.type = 'text/javascript';
   script.src = 'js/jquery.js';
   head.appendChild(script); 
}
like image 160
Renfro Avatar answered Oct 16 '22 07:10

Renfro