检查 jQuery 是否包含在 Header (Joomla) 中 [英] Check if jQuery is included in Header (Joomla)

查看:21
本文介绍了检查 jQuery 是否包含在 Header (Joomla) 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检查是否使用 PHP 加载了 jQuery?

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

我在 Joomla 中有两个不同的插件来加载 jQuery JS,但是当它被多次包含时它不能正常工作.

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.

再解释一下这个过程:Joomla 提供了在呈现 HTML 源代码之前拦截它的能力,本质上是处理源代码本身.

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.

这是使用函数:

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

$row 是页面可以解析的 HTML 内容.

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

我在想也许 preg_match 可以工作,但没有太多经验.

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

推荐答案

更好的是,您可以使用 JavaScript 进行验证,然后在缺少时将其添加到头部.

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); 
}

这篇关于检查 jQuery 是否包含在 Header (Joomla) 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆