简体   繁体   English

外部js脚本中图像的相对路径

[英]relative path to images in external js script

I'm writing a component in Joomla and want to use JavaScript. 我正在Joomla中编写组件,并想使用JavaScript。

I got the JavaScript part working in a separat test html page, but now I want to include it in the Joomla component. 我在分离测试html页面中使用了JavaScript部分,但现在我想将其包含在Joomla组件中。

The problem is the relative file paths for the images. 问题是图像的相对文件路径。 The images are stored in the media folder of joomla: 图像存储在joomla的媒体文件夹中:

media/com_component/images 媒体/ com_component /图像

I include the external js-file with this command: 我在此命令中包含外部js文件:

$document->addScript(JURI::Root().'components/com_component/script.js'); $ document-> addScript(JURI :: Root()。'components / com_component / script.js');

In the script I need the path to the image folder. 在脚本中,我需要图像文件夹的路径。 I don't want to hard code the absolute path in the script. 我不想在脚本中硬编码绝对路径。 How can I get the relative paths? 如何获得相对路径? Do/can I use Joomla functions for that? 是否可以为此使用Joomla函数?

Thank you 谢谢

I chose to put the file path information in the css file (set the image as the background of the link). 我选择将文件路径信息放入css文件中(将图像设置为链接的背景)。 This way the js-script is independent of the image's file path. 这样,js脚本就独立于图像的文件路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM