Check if jQuery is included in Header (Joomla)(检查 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) 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检查 jQuery 是否包含在 Header (Joomla) 中
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
