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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With