Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在joomla头上添加js_Javascript_Joomla_Head - Fatal编程技术网

Javascript 在joomla头上添加js

Javascript 在joomla头上添加js,javascript,joomla,head,Javascript,Joomla,Head,如何在joomla head部分实现下面的js。我曾多次尝试添加此代码,但在对index.php文件进行修改后,在查看查看页面源代码后,它不会保存在head部分,而是显示在body部分下 <script type='text/javascript'> (function() { var useSSL = 'https:' == document.location.protocol; var src = (useSSL ? 'https:' : 'h

如何在joomla head部分实现下面的js。我曾多次尝试添加此代码,但在对index.php文件进行修改后,在查看查看页面源代码后,它不会保存在head部分,而是显示在body部分下

     <script type='text/javascript'>
   (function() {
     var useSSL = 'https:' == document.location.protocol;
     var src = (useSSL ? 'https:' : 'http:') +
         '//www.googletagservices.com/tag/js/gpt.js';
     document.write('<scr' + 'ipt src="' + src + '"></scr' + 'ipt>');
   })();
 </script>

 <script type='text/javascript'>
 googletag.cmd.push(function() {
 googletag.defineSlot('/20819282/mpbd_top_header', [728, 90], 'div-gpt-ad-1452863082329-0').addService(googletag.pubads());
 googletag.pubads().enableSyncRendering();
 googletag.enableServices();
 });
 </script>

(功能(){
var usesssl='https:'==document.location.protocol;
var src=(使用SSL?'https:':'http:')+
“//www.googletagservices.com/tag/js/gpt.js”;
文件。写(“”);
})();
googletag.cmd.push(函数(){
googletag.defineSlot(“/20819282/mpbd_top_header”,[728,90],“div-gpt-ad-145286308229-0”).addService(googletag.pubads());
googletag.pubads().enableSyncRendering();
googletag.enableServices();
});

将代码添加到head部分的/templates/{yourtemplate}/index.php,代码将显示在head部分。如果您使用的是一些特殊的模板,那么事情可能会稍微复杂一些,但这是一般的想法

无法更改默认protostar模板中的代码。在下一次Joomla更新之后,您的更改将被删除

因为这很可能不是您想要对模板所做的唯一更改,所以首先,创建模板的副本,重命名它,安装它,并配置Joomla以使用它。这将使更改在更新期间保持不变

然后找到文件templates/your_new_template\u name/index.php,在标题部分末尾之前粘贴代码,使其看起来像这样

<script 
....
</script>
</head>

从JED:下载并安装此模块

创建一个名为myscript.js的新文件

将以下行添加到myscript.js并将其保存到服务器的web根目录(/public\u html/)

(函数(){
var usesssl='https:'==document.location.protocol;
var src=(使用SSL?'https:':'http:')+
“//www.googletagservices.com/tag/js/gpt.js”;
文件。写(“”);
})();
googletag.cmd.push(函数(){
googletag.defineSlot(“/20819282/mpbd_top_header”,[728,90],“div-gpt-ad-145286308229-0”).addService(googletag.pubads());
googletag.pubads().enableSyncRendering();
googletag.enableServices();
});
在后端,转到Extensions>Modules并单击Flexi代码模块的空条目

将位置设置为“调试”,将模块标题设置为“我的脚本”(或WAHT,无论何时命名),并将标题设置为“隐藏”

代码框下面有4个选项,将第一个使用PHP的选项保持在打开状态,并关闭其他3个选项

在“代码”框中输入以下文本:

这将在当前模板的头部添加myscript.js文件作为包含文件,而无需编辑模板文件本身


整个过程应该不超过5分钟。

您需要提供更多信息。哪个文件是index.php。它看起来怎么样?它是否在您的模板中,然后您使用的是什么模板,等等。是的,这是我的模板index.php文件,我尝试在标题部分添加js。我使用的是joomla默认protostar模板。感谢您的r我尝试了上述过程(重命名模板)但是没有结果。它仍然在正文部分。你怀疑还有什么其他的吗?我的url:我建议你在joomla.stackexchange网站上发布,因为stackoverflow确实是为开发人员提供的,而在那里你可能会找到更多的支持。但是请继续并获取一个专用的扩展,它更简单、更有效;而且是免费的。
(function() {
 var useSSL = 'https:' == document.location.protocol;
 var src = (useSSL ? 'https:' : 'http:') +
     '//www.googletagservices.com/tag/js/gpt.js';
 document.write('<scr' + 'ipt src="' + src + '"></scr' + 'ipt>');
 })();

googletag.cmd.push(function() {
googletag.defineSlot('/20819282/mpbd_top_header', [728, 90], 'div-gpt-ad-1452863082329-0').addService(googletag.pubads());
googletag.pubads().enableSyncRendering();
googletag.enableServices();
});