如何将javascript添加到joomla模块?
您好,我在将 javascript 添加到 joomla 模块时遇到问题。我找到了一些解决方案,但它不起作用。
$document = &JFactory::getDocument();
$document->addScript("/career.js");
我的模块中有这两行,但脚本不在渲染的站点中。 该文件位于我的网站的根目录中(仅用于测试目的)。
感谢您的帮助
Hi I have problem with adding javascript into a joomla module..I've found some solution, but it's not working..
$document = &JFactory::getDocument();
$document->addScript("/career.js");
These two lines I have in my module, but the script isn't in rendered site..
The file is in root of my web (for test purposes only).
Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
试试这个,效果很好。
Try this, it's working perfectly.
检查查看源代码。
复制粘贴career.js的路径作为浏览器url并尝试访问它。
根据需要更改路径。
check the view source .
copy paste the path of the career.js as browser url and try to access it.
Change the path as needed.
您可以使用以下扩展(适用于 1.5 和 1.6)轻松包含自定义 javascript 或 HTML。
http://extensions.joomla.org/extensions/edition/custom -code-in-modules/5435
另外,当您直接使用时,可以使用像这样的完整路径(更改.JS的路径)
You can Use following extension (works both 1.5 and 1.6) to include custom javascript or HTML easily.
http://extensions.joomla.org/extensions/edition/custom-code-in-modules/5435
Also when you use directly may use full path like this (change the path of your .JS)
因此,唯一适合我的解决方法就是将此 js 添加到我网站的模板中。但它的解决方案非常糟糕,因为我只需要在一篇文章/模块中使用它
So only workaround which works for me is to add this js to template of my site..But its really awful solution, since I only need it in one article/module
您还可以使用 joomla php 模块
http://www.fijiwebdesign.com/products/joomla-php-module.html
或者您可能在以下位置找到了更适合您需求的模块:
http://extensions.joomla.org/extensions/edition/custom-code -模块内
You could also use the joomla php module
http://www.fijiwebdesign.com/products/joomla-php-module.html
or maybe you found a module that better fits your needs at:
http://extensions.joomla.org/extensions/edition/custom-code-in-modules
哎呀..主要问题是,我正在加载包含带有javascript的自定义模块的页面是通过ajax加载的..所有插件似乎都将js代码添加到head中,而我只将一些元素替换到页面正文中。
这个问题有一些解决方案吗?我知道我可以将所有 js 逻辑放入一个文件中,但我不确定这是一个好方法。是否可以以某种方式将 js 直接包含到模块中?这样脚本标签将位于我的文档正文中并正确包含(我不确定代码是否会被触发?)
谢谢
Ouch..The main problem is, that I am loading the page containing custom module with javascript is loaded via ajax..And all the plugins seems to be adding the js code into head and I only replace some elements into body of my page.
exist some solution to this problem?I know I can have all the js logic into one file, but I am not sure it is good way. Is somehow possible to include js directly to module?So that the script tag will be within my document body and correctly included (i am not sure the code will be fired??)
Thanks
确保
模板 index.php 中的 head 标记后有此内容
Make sure that you have this
after head tag in template index.php
对于所有稍后登陆此页面并在 Joomla 3.x 中寻找解决方案的人,
您可以包含一个“自定义 HTML 高级”类型的模块,该模块不会过滤掉任何脚本或样式标签。
您可以在任何您想要的页面上使用它。
希望这对您有帮助:)
For all those who are landing on this page at a much later date, and looking for solution in Joomla 3.x
You can include a module of type "Custom HTML Advanced" which will NOT filter out any script or style tags.
You can use it on any of the pages you want.
Hope this helps you :)