Placing content in a .js file

3 posts by 2 authors in: Forums > CMS Builder
Last Post: October 26, 2022   (RSS)

I am building a site that has background images that are controlled from a .js file, so my question is; how do I place the image upload code in the .js file instead of in the .php file? I have attached the .js file and the area that I need to change is on line 174.


splitex.js 11K

By Dave - October 26, 2022

Hi MercerDesign, 

What you can do is try creating a copy of splitex.js and saving it as splitex.php.js.

Then add this line to the very top of the file: 

header("Content-Type: application/javascript");

Followed by any other PHP code you need.  Just make sure when you view source of the .php.js file it's valid js.

Hope that helps!

Dave Edis - Senior Developer

By Dave - October 26, 2022

Sorry, correction.  You want to name the file with a .js.php ending, so splitex.js.php.  

This will have the server execute it as PHP code, but because your sending the javascript header the browser will interpret it as javascript code.

Dave Edis - Senior Developer