简体   繁体   中英

Javascript: Get full path to a directory

I'm using lightbox with a WordPress theme. It has defined some images path in the lightbox.js file. For example

this.fileLoadingImage = '/images/lb-loading.gif';

So if I change the above path to following to get the images from the theme directory:

this.fileLoadingImage = 'wp-content/themes/mytheme/images/lb-loading.gif';

It will work on homepage only. But it won't work on other pages. This the above path is not valid on the other pages. So how can I get the full path to the image directory dynamically?

If you want the image to be seen on all pages, you must use an absolute path. Try adding a / before wp-content like so:

this.fileLoadingImage = '/wp-content/themes/mytheme/images/lb-loading.gif';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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