Placing content in a .js file

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

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